Learn, Share, Build

September 20, 2017, at 8:53 PM

As a Java developer who switches between *NIX systems (OS X, Ubuntu, ...), although I can always "get" my JDK up and running, it seems that there is no clear definition of JAVA_HOME in many packages which require JAVA_HOME to be set :

For example

  • MAVEN : "JAVA_HOME, refers to your JDK directory"
  • HADOOP : "JAVA_HOME, which specifies the path to the Java 1.5.x installation"
  • SUN : "JAVA_HOME is the directory that contains the JRE"

I thus have 2 questions regarding this matter (any insights would be welcome, also, but concretely, I have these two questions) :

1) Does mac os X java installation copy the target from the "JavaVM.frameworks" directory into usr/bin ?

2) What is the "definition" of JAVA_HOME ? Clearly, we cannot define JAVA_HOME as simply "the place where java is installed", because this definition is ambiguous, since java can exist both in a HOME location (i.e. in /System/Library/Fraemworks/.....) , or alternatively, it may also be directly in the /usr/bin directory ?


I believe that JAVA_HOME is ACTUALLY meant to refer to more than just a binary "java" program. JAVA_HOME probably is meant to refer to the location of a set of java related directories AND binaries... But still, I am not really clear what this comprises, and wether or not this definition which I am proposing is precise enough to be useful.

Answer 1

There is no "true" definition of JAVA_HOME. This variable is not used by the Java Runtime Environment, and has no specification as part of the Java platform.

It is merely a convention that is used by some applications that run on top of the Java platform. Since there's no standard, each application is free to make its own rules about the directory to which this variable should refer; you should read the application's documentation to find out what it needs.

That said, every application I've found that uses this variable will work if you set it to the top level directory of a JDK installation (not the JRE within the JDK, but the JDK itself). This directory should contain "bin" and "lib" subdirectories that contain the java executable and the runtime libraries, respectively.

Some applications will also work if you point it at a JRE, but if it needs development tools like javac, it will fail.

Usually, I specify JAVA_HOME on the command line when I run a tool than needs it, because I work with multiple versions of Java, like this:

JAVA_HOME=/usr/local/jdk1.6.0_29 ant
Answer 2

I would define it like the path such:


where the executable that will run your programs is.

The source root to look for all your SDK JRE files and jars.

Answer 3

Sun's convention refers to java home as the jre root dir. This should be the more authoritative definition.

For dev tools like maven, they would mostly care about jdk dir. They should have called it "JDK home". Unfortunately many call it "java home" too, hence the confusion.

We can break the confusion by not using "java home"; instead, say "jre home" or "jdk home" for clarity.

Answer 4

I don't know about what it is set to on different systems, but JAVA_HOME should be set to the root of the java installation. So if you have it installed to

C:\Program Files\Java\jdk1.6.0_25\

JAVA_HOME should be set to that.

Similar to JDK_HOME if you see that in writing.

Answer 5

JAVA_HOME should point to the installation directory of the Java installation you want to use.

Rent Charter Buses Company
Learn, Share, Build

Learn, Share, Build

The simplified version I have looks like this:

Learn, Share, Build

Learn, Share, Build

I have 2 types: AdvisorId,TeacherIdeach have some strings and floats I want to use them in my MyBatis mapper, I am trying to do it this way:

Learn, Share, Build

Learn, Share, Build

i am developing a micro service based systemit need to input user interactions such as action taken,action taken by,updated date,multiple comments for all the services

Learn, Share, Build

Learn, Share, Build

Java based web application on a tomcat server with Oracle DB and AngularJS front end