I am trying to install java 11 on an amazon ec2 instance Linux , I followed the below steps:
====OS details=====
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]# cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
===Install Java=====
sudo amazon-linux-extras
sudo amazon-linux-extras install java-openjdk11 -y
java --version
sudo su -
echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64" >> .bash_profile
echo "export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64/bin" >> .bash_profile
source ~/.bash_profile
echo $JAVA_HOME
java --version
installation result: java is successfully installed and even path is also set
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]# cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User-specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64/bin
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]#
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]#
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]# echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]# rpm -qa | grep jdk
java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64
copy-jdk-configs-3.3-10.amzn2.noarch
java-11-openjdk-headless-11.0.16.0.8-1.amzn2.0.1.x86_64
[root#ip-172-31-44-83 java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64]#
When I am adding a java path in Jenkins global tool Configuration getting the below error
"/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64 doesn’t look like a JDK directory
"
Look like the location you are specifying doesn't have javac.
to make sure try to check if javac exist or not by running:
ls /usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64/bin/javac
if it does not exist then try to download fresh JDK and set JAVA_HOME point to there.
For the past 2 weeks I've been busy trying to figure out how to setup my minecraft server onto my freenas server.
I was able to get it up and running stably when going into the jail manually typing in my startup command:
cd /root/Minecraft_Server
java -Xmx4096M -Xms4096M -jar forge-1.12.2-14.23.4.2757-universal.jar
And then just close the shell.
I tried looking to automate this command and put it into and sh file in crontab and everything, that didn't work so i decided to upgrade to 11.2 to see if that has any solutions.
Now the main problem already is that if I try to run my command manually in the shell, and i leave the webui, it will just close the server down to unlike in the 11.1 freenas.
Does anyone have any more ideas here?
In the same location as the server I have a minecraft.sh script with this command.
If I manually run the script it works, but if I use crontab it won't start it either.
The corntab command that i've used is:
#reboot /root/Minecraft_Server/minecraft.sh
I also tried putting in the command directly but this also was useless.
I even tried the exec.poststart but when i direct it to /root/minecraft_Server/minecraft.sh it won't start either, it won't even run the jail anymore
use “screen java ...”
on relog to shell do screen -x to get on the server shell
You can configure your Java command as a service that starts whenever the jail starts. That way, the Java server doesn’t depend on the shell or webui.
Basically, create a usr/local/etc/rc.d/minecraftd file that includes the following script:
#!/bin/sh
#
# PROVIDE: minecraftd
# REQUIRE: LOGIN DAEMON NETWORKING mountcritlocal
# KEYWORD: shutdown
#
# Use the following variables to configure the minecraft server. For example, to
# configure the ON/OFF knob variable:
# sysrc minecraftd_enable="YES"
#
# minecraftd_enable="YES"
# minecraftd_user_dir="/root/minecraft"
# minecraftd_jar_path="/root/minecraft/server.jar"
# minecraftd_java_opts="-Xms512M -Xmx1024M"
. /etc/rc.subr
name=minecraftd
rcvar=`set_rcvar`
pidfile=/var/run/minecraftd.pid
load_rc_config $name
start_cmd="${name}_start"
: ${minecraftd_enable="NO"}
: ${minecraftd_user_dir="/root/minecraft"}
: ${minecraftd_jar_path="/root/minecraft/server.jar"}
: ${minecraftd_java_opts="-Xms512M -Xmx1024M"}
minecraftd_start() {
if [ -e $pidfile ]; then
echo "$name already running."
else
echo "Starting $name..."
/usr/sbin/daemon -f -p $pidfile \
/usr/local/bin/java -Duser.dir=$minecraftd_user_dir \
$minecraftd_java_opts \
-jar $minecraftd_jar_path nogui
echo "$name started."
fi
}
run_rc_command $1
Then configure the service to start on boot:
sysrc minecraftd_enable="YES"
And restart your jail.
For more information, check Installing a Minecraft server on FreeNAS.
Disclaimer: My team published that article.
Hope this helps somebody.
I have written a unix program with a sample code as follows :
export PATH=/usr/java5/jre/bin:$PATH
export JAVA_HOME=/usr/java5/jre/bin
export MW_HOME=$UCM_HOME/Middleware
export CLASSPATH=$MW_HOME:$MW_HOME/eaton/
# Verify whether required variables are set
if [ -z "${JAVA_HOME}" ]; then
printf "\n\nError: Set the following environment variables:\n\n"
printf "JAVA_HOME (Absolute path to jdk directory)\n\n"
exit 1
fi
JAVACMD="${JAVA_HOME}/java"
LIB="${UCM_HOME}/generic/oracle.ucm.fa_genericclient_11.1.1.jar"
config_file="${UCM_HOME}/generic"
echo $config_file
echo "${config_file}/connection.properties"
# jrf-client.jar is a manifest jar with MANIFEST.MF Class-Path referencing required client libraries
CUSTOM_CLASSPATH=$MW_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-client.jar
checkerror()
{
RESULTCODE=$?
if [ ${RESULTCODE} -ne 0 ];then
exit 1
fi
}
${JAVACMD} -Xms512m \
-classpath "${CLASSPATH}:${LIB}" \
-Ducm.prop.default="${config_file}/connection.properties" \
test.oracle.apps.tx.GenericToolUpload "${FILE_LOCATION}/${FILE_NAME}" "${ENTITY_LIST}"
checkerror
exit
When i am executing this program. It is going into error with-
JVMJ9GC020E -Xms too large for heap
JVMJ9VM015W Initialization error for library j9gc23(2): Failed to initialize
Could not create the Java virtual machine.
user profile was set with 256M. I have increased to 512M
But I am still getting the same error.
I think it is erroring out in ${JAVACMD} -Xms512m \ . But do not know the solution.
I used to have multiple JDK installed on my Linux machine, and I like to switch from one version to another from the command-line ( I used to change my JAVA_HOME manually):
This is my current approach :
I source a ~/.paths in my .bashrc.
the .paths contain all the JDK installed on my machine.
JDK7="~/local/jdk1.7.0_15"
JDK8="~/local/jdk1.8.0"
// I use Jdk 7 by default
JDK_HOME=$JDK7;
// including $JDK_HOME/bin to the $PATH
When I want t switch to JDK8, I modify the JDK_HOME variable to point on JDK8 in the file, and I re-source my .paths file.
I know that IDE can manage multiple JDK easily, but I want an rvm like solution.
Is there any better trick ?
Better more, Is there any equivalent for rvm in Java ?
There is jdk_switcher although it is quite static to some ubuntu paths - it should be easy to modify it to run from other paths.
There is a plan to make RVM 2 support switching more then just Ruby versions, you can read more about it here.
anyone with the link can comment.
I don't think there is such solution.
See this question to a solution with symlinks.
Now , I'm using jdk-manager, a little bash script to manage multiple JDKS installations.
You can have as many Java versions installed as you want to. Just install to a folder of your choosing and use some convention.
If you want to make one-time use of a particular version run it with a full path (for example):
>C:\java\jdk-6u35\bin\java.exe
or
>/java/jdk-6u35/bin/java.exe
If you want to change to just use it, change your path to put the version you want at the front. The path might be similar to that shown above.
Be sure to change JAVA_HOME as well and any other environment settings that include a reference to the java location.
Note that some tools have internal configuration as to which java version to use. Eclipse is a good example. You have to set up a list of your JVMs and then select one for each project or for all projects.
I wrote my own script to manage java versions. I use some sites that require Oracle Java and usually the latest version, so I can't use apt/aptitude and therefore can't use update-alternatives or jdk-manager (which uses update-alternatives).
Here's my script. I don't develop professionally, so it's probably a mess, but it serves my purposes. It only considers java versions stored in /usr/lib/jvm.
#!/bin/bash
# the proper way....
# + update: update-alternatives only works for versions installed by apt or aptitude
# ... same for jdk-manager (uses update-alternatives to do the heavy lifting)
#echo "The proper way is:"
#echo "$ update-alternatives --config java"
#exit
# the rest is (no longer) depreciated....
echo "The current default java is $(readlink --canonicalize `which java`)"
PS3='Select Java to install: '
options=( $(find /usr/lib/jvm -iname java) )
noptions=${#options[#]}
(( loption=noptions-1 ))
options[${#options[#]}]="Quit"
select opt in "${options[#]}"
do
for i in $(seq 0 $loption); do
[ "$opt" == "${options[$i]}" ] && \
javapath=${options[$i]}
done
if [ "$javapath" ]; then
break
fi
if [ "$opt" == "Quit" ]; then
echo "Nothing installed.";
exit
else
echo "Invalid option. Try another one.";
continue
fi
done
# remove the old link (might be superfluous)
#rm -vf -- "$link"
# set new link (symbolic, force, verbose)
sudo ln -sTfv "$javapath" "/usr/bin/java"
default_java_dir=$(echo "$javapath" | grep --only-matching --regexp="\/usr\/lib\/jvm\/[^\/]*")
sudo ln -sTfv "$default_java_dir" "/usr/lib/jvm/default-java"
java_bin_dir=$(echo "$javapath" | sed 's/[^\/]*$//')
echo $java_bin_dir
[ -f "${java_bin_dir}javac" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javac"
[ -f "${java_bin_dir}javadoc" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javadoc"
[ -f "${java_bin_dir}javafxpackager" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javafxpackager"
[ -f "${java_bin_dir}javah" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javah"
[ -f "${java_bin_dir}javap" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javap"
[ -f "${java_bin_dir}java-rmi.cgi" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}java-rmi.cgi"
[ -f "${java_bin_dir}java_vm" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}java_vm"
[ -f "${java_bin_dir}javaws" ] && sudo ln -sfv -t "/usr/bin" "${java_bin_dir}javaws"
find_dir=$(dirname "$java_bin_dir")
pluginpath=$(find "$find_dir" -name libnpjp2.so)
#exit
echo -n "Install $pluginpath as the Java plugin? [y/N]: "
read
response=$(echo $REPLY | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/')
if [ "${response:0:1}" == "Y" ]; then
# directories for plugins
plugin_dirs="/usr/lib/firefox/plugins
/usr/lib/firefox-addons/plugins
/usr/lib/mozilla/plugins
/opt/google/chrome
/home/james/.mozilla/plugins"
# first, clean out anything we might have improperly installed already
echo "Using 'sudo' to remove any installed java plugins..."
for pdir in $plugin_dirs; do
sudo rm --verbose --force "$pdir/libjavaplugin_oji.so" "$pdir/libnpjp2.so" "$pdir/IcedTeaPlugin.so"
done
# okay, trying brute force and awkwardness....
echo "Using 'sudo' to install \"$pluginpath\" in several places..."
for pdir in $plugin_dirs; do
sudo ln --symbolic --verbose --force "$pluginpath" "$pdir"
done
fi
exit
If you use Debian or a derived GNU/Linux distribution, you can use update alternatives to set what is currently being run when you type java.
Try typing
update-alternatives --display java
That will show you what alternatives you have available.
This command is non-destructive, that is, it doesn't change anything.
man update-alternatives
Will give you the manual for the tool.
The command you will likely want though is:
update-alternatives --config java
Which will give you a simple, interactive way of setting the java program. You can also use --set if you want to script it.
Of course, you should not trust me without running man first, because people sometimes go on the Internet and tell lies. ;)
EDIT: I forgot, this link introduces update-alternatives in a good (if Vi specific) way.
For Linux, you can use update-alternatives to not only set paths to java, javac, and other binaries but also your JAVA_HOME. Since all it does is manage links, you can install a link to your jdk directories and then set JAVA_HOME to point to that link. For example, "update-alternatives --install /usr/lib/jdk jdk /path/to/jdk8 1" will install a link to your jdk directory. You then add "export JAVA_HOME to /usr/lib/jdk" in .bashrc, .profile, or whatever file you use to set environment variables and any alternative you install under the name jdk will be pointed to by JAVA_HOME when you switch with update-alternatives --config jdk. If you are using alternatives already for the java executables, you can use --slave to make jdk whenever java does.
Using openSUSE, I downloaded the Oracle rpms for jdk1.6.0_24 and I want to set the java home environment variable to /usr/java/jdk1.6.0_24 but the /etc/alternatives system is unable to automatically detect this installed JDK. Update-alternatives , or whatever just doesn't find the jdk.
So, I want to detect the JAVA home manually in a BASH script.
If I run this command: sudo find /usr -name 'jdk1.6*' , I get this result:
/usr/java/jdk1.6.0_24
How do pipe that result into a environment variable? I want to do something like
#!/bin/bash
read in JAVA_HOME var from a file
if file doesnt exist
sudo find /usr -name 'jdk1.6*'
prompt user for which jdk is correct
set that choice to a variable
add the JDK to alternatives if it is missing
save variable to a file and dont prompt next time
set the alternatives java choice
fi
echo $JAVA_HOME
something like
#!/bin/bash
function validate_java_home {
if [ -z ${JAVA_HOME} ]
then
# do something if the file doesn't provide ${JAVA_HOME}
else
if [ ! -e ${JAVA_HOME} ]
then
# do something if the file provides a non existent ${JAVA_HOME}
fi
fi
}
if [ ! -e ${YOUR_FILE_NAME_CONTAINING_JAVA_HOME} ]
then
JAVA_HOME_CANDIDATES=$(find /usr -name 'jdk1.6*')
echo "Found the following candidates for JAVA_HOME, reply with the one you want then press return"
echo ""
echo $JAVA_HOME_CANDIDATES
read USER_SUBMITTED_JAVA_HOME
echo "You chose $USER_SUBMITTED_JAVA_HOME"
JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
else
. ${YOUR_FILE_NAME_CONTAINING_JAVA_HOME}
fi
validate_java_home
export ${JAVA_HOME}
I haven't tested that but hopefully you get the gist (and I'd say using select as per glenn jackman's answer is more concise/friendly, didn't know that existed so I'm glad I read this Q!)
oldIFS="$IFS"
IFS=$'\n'
choices=( $(find /usr/java -type d -maxdepth 1 -print) )
select choice in "${choices[#]}"; do
[[ "$choice" ]] && break
done
IFS="$oldIFS"
export JAVA_HOME="$choice"
Not sitting at a linux terminal, but this should get you going:
...
jdkpath=`sudo find /usr -name 'jdk1.6*'`
export JAVA_HOME=$jdkpath
...
Adjust as needed.
Based on Matt's answer , here is the script I am using:
#!/bin/bash
# JAVA_HOME script for RPM based java installations
# http://www.oracle.com/technetwork/java/javase/install-linux-64-rpm-138254.html
# examine and understand /etc/alternatives before you run this
cd $SITE_HOME
function set_java_home {
if [ -z $JAVA_HOME ]; then
echo "Using default value for JAVA_HOME: /usr/java/default"
JAVA_HOME=/usr/java/default
fi
export -p JAVA_HOME
echo $JAVA_HOME > java.home.config
echo "JAVA_HOME variable set to $JAVA_HOME ."
}
if [ -f java.home.config ]; then
JAVA_HOME=$(<java.home.config)
else
JAVA_HOME_CANDIDATES=$(find /usr -type d -name 'jdk1.6*')
echo "Found the following candidates for JAVA_HOME. Pick one: "
echo "---"
echo $JAVA_HOME_CANDIDATES
echo "---"
read USER_SUBMITTED_JAVA_HOME
echo "You chose $USER_SUBMITTED_JAVA_HOME ."
JAVA_HOME=${USER_SUBMITTED_JAVA_HOME}
fi
# Set the variable
set_java_home