Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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 4 '11 at 20:44
    
That depends. Are you talking about when you develop or for a production system? –  Bittrance Apr 4 '11 at 20:44
1  
@ErikA "we all know who you are" ---- oyoyoy, have I asked that many dumb questions already? :) –  Genadinik Apr 4 '11 at 20:53
    
@Bittrance this is for a development environment –  Genadinik Apr 4 '11 at 20:53
    
hah, no...your signature/profile block gets posted automatically as you no doubt already know. –  EEAA Apr 4 '11 at 20:54
add comment

2 Answers

up vote 6 down vote accepted

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.

share|improve this answer
    
Also you can run export JAVA_HOME=/usr/lib/jvm/ to just set JAVA_HOME for one shell session. –  Jason Axelson Apr 5 '11 at 0:14
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.