3

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?

EEAA
  • 109,363
  • 18
  • 175
  • 245
Genadinik
  • 1,103
  • 4
  • 19
  • 39
  • 1
    No need to post a greeting or sign your posts. Just post the question itself. We all know who you are, and your acceptance of our answers is thanks enough. :) – EEAA Apr 04 '11 at 20:44
  • That depends. Are you talking about when you develop or for a production system? – Bittrance Apr 04 '11 at 20:44
  • 1
    @ErikA "we all know who you are" ---- oyoyoy, have I asked that many dumb questions already? :) – Genadinik Apr 04 '11 at 20:53
  • @Bittrance this is for a development environment – Genadinik Apr 04 '11 at 20:53
  • hah, no...your signature/profile block gets posted automatically as you no doubt already know. – EEAA Apr 04 '11 at 20:54

2 Answers2

6

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:

$ JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun mvn package

Which means to set JAVA_HOME for this command only.

Bittrance
  • 3,070
  • 3
  • 24
  • 27
0

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
djangofan
  • 4,182
  • 10
  • 46
  • 59