I am trying to configure Tomcat to know where JAVA_HOME is. I am used to Windows :) ...which file should I edit to add the Java info, and where is it located?
If your shell is bash (echo $SHELL -> /bin/bash) you may want to add a JAVA_HOME entry in /home/<user>/.bashrc. However, note that if you only work with one Java version, you should install the package and no explicit JAVA_HOME setting should be necessary for most scenarios.
Also, it is sometimes convenient to do something like this:
Using Oracle JDK, here is how I set mine. Don't forget the "-p" in your export command.
# Set the JAVA_HOME variable
function set_java_home {
echo "Searching for java ..."
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
sudo rm /etc/alternatives/java
sudo ln -s $JAVA_HOME/bin/java /etc/alternatives/java
echo "JAVA_HOME variable set to $JAVA_HOME and /etc/alternatives set."
}
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_java_home
For development work:
If your shell is bash (echo $SHELL -> /bin/bash) you may want to add a JAVA_HOME entry in /home/<user>/.bashrc. However, note that if you only work with one Java version, you should install the package and no explicit JAVA_HOME setting should be necessary for most scenarios.
Also, it is sometimes convenient to do something like this:
Which means to set JAVA_HOME for this command only.
Using Oracle JDK, here is how I set mine. Don't forget the "-p" in your export command.