WhatIf
WhatIf

Reputation: 643

JAVA_HOME : where is java installed

I'm trying to set the JAVA_HOME to get tomcat 7 to work with no success.

I'm using CentOS 6.3. Here is what I did so far:

which java /usr/bin/java

so I edited the .bash_profile, I added

export JAVA_HOME=/usr/bin/java

didn't work. I searched online and found another user on stackoverflow who found it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java

I searched on my computer and found that java is located in /usr/lib/jvm/jre-1.6.0-openjdk/bin

I then changed the JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/bin , tried to start tomcat but server can't be found.

How do I find where java was installed? I didn't install it myself; it was installed during linux installation.

Thanks in advance, Mike

Upvotes: 4

Views: 25739

Answers (3)

Animesh Srivastava
Animesh Srivastava

Reputation: 89

/usr/bin contains all your binaries; your actual JRE or JVM maybe installed elsewhere so you can run a simple command at /usr/bin to get the actual location of java.

ls -lrt

A binary may appear like (soft links):

java -> /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java

Okay; now that we know where the java installation is we can now export the JAVA_HOME to one folder above bin i.e /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/.

export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/

Upvotes: 0

Stephen C
Stephen C

Reputation: 718698

The strictly correct answer is this:

export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk

The issue is that on a typical Linux system you access the java command (etc) via symbolic links that are created / managed by the alternatives command. This allows you to make a system-wide choice over which of the java installations should be used by default; i.e. via commands in /usr/bin.

The second issue this that the JAVA_HOME environment variable should point at the Java installation directory. The "bin" directory is a subdirectory of the installation directory. (Look at the contents of "/usr/lib/jvm/jre-1.6.0-openjdk" !!)

While export JAVA_HOME=/usr/bin will work for locating the commands, it won't work if the Java application needs to find other files in the installation; e.g. the "rt.jar" file.

This "fine distinction" possibly doesn't matter for Tomcat, but it is likely to matter for other Java software that uses the JAVA_HOME convention.


Footnote: if you are using an Oracle Java for Linux installation, the default installation directory will be a subdirectory "/usr/java". Sadly, the Oracle installer doesn't understand that Linux "alternatives" system. You either have to register the alternatives for each of the Java commands by hand (tedious!!) or add the installation's "bin" directory to your PATH.

Upvotes: 3

Diego Basch
Diego Basch

Reputation: 13059

export JAVA_HOME=/usr should do it. The script runs $JAVA_HOME/bin/java

Upvotes: 12

Related Questions