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 ?
MY THOUGHTS
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.
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
I would define it like the path such:
`JAVA_HOME\bin\java`
where the executable that will run your programs is.
The source root to look for all your SDK JRE files and jars.
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.
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.
JAVA_HOME should point to the installation directory of the Java installation you want to use.
Related
In the windows environment variable the JAVA_HOME path needs to be updated after each time upgrading the JDK/JRE. Is there any solution for this to maintain the default path for JAVA_HOME irrespective of the version it gets upgraded?
Let me know if anyone has any solution for this.
we tried of setting the new path while installing the JRE, even this path changes after upgrading the JRE.
By default, (Oracle) Java installers for Windows put the installation in directory whose name matches the Java version and patch number; e.g.
C:\Program Files\Java\jdk1.6.0_30
This allows you to have multiple different versions of Java installed. That's a good thing because a lot of applications require a particular Java version. And to that end, you probably want to use different Java versions for different applications.
However, if you want a default version that you can easily change without changing lots of classpath settings in lots of places, the obvious way to do it is to use a symbolic link or symlink. For example:
C: Program Files:
Java:
jdk1.6.0_30:
...
jdk1.8.0_77:
...
default -> jdk1.8.0_77
Then your use C:\Program Files\Java\default\bin in %PATH% and C:\Program Files\Java\default in %JAVA_HOME%, and similarly change any -cp options in batch files, etc.
Once you have done all of that, you can switch to a different default Java version, by simply updating the target for the default symlink to a different installation directory.
Note that Linux has a more sophisticated way of doing this using the alternative utilities. But under the hood that is all done with symlinks.
I've been setting Windows environment variables (like JAVA_HOME) every time I installed a Java update. (As per Environment variables for java installation).
However, I've recently noticed that Java updates add C:\ProgramData\Oracle\Java\javapath; to the System Path (not the User Path). I removed JAVA_HOME, etc from my User Path, and java -version seems to work from any directory.
Does that mean that it is not necessary to do that simple but annoying task with each Java update?
That depends on what you are trying to do.
Generally, you don't need JAVA_HOME to run a Java app. Adding the location of the Java binaries to the PATH is sufficient for Windows to find and execute them.
However, e.g. a lot of application servers like Tomcat and build tools like Gradle will use JAVA_HOME to determine the location of your Java installation.
Java itself does not use JAVA_HOME. Some third-party things like IDEs and Tomcat do. I've never set it as an environment variable in 20 years.
Personally, I don't even have JAVA_HOME set and I've been developing at this company for 6 years now (and other companies for 10+ years). To me, it tends to get in the way. The last install sets the windows path which generally isn't what my IDE's, Tomcat, JBoss or SOAP-UI support so I just edit all their startup files to choose/set the JAVA_HOME they work with.
Target Environment
Windows 7 (6.1)
Java 1.8.0_121 64bit
I recently created a minimal java environment consisting of just the single file java.exe in a newly created, empty directory and successfully ran a simple HelloWorld.class file simply by copying it to the same directory and typing:
.\java HelloWorld
I found this kind of surprising, and wondered if maybe because the version of java I was using (jre 1.8.0_72) had been installed from an .exe file whether there was something in the Windows registry telling java.exe where to find rt.jar and such.
Running the java control panel, you can certainly see java 1.8.0_72 is in there:
I if I used a java version which was NOT installed (i.e. a standalone java version) would I get a different result?
Well, before trying a stand-alone version I think I'll try a computer having NO java on it at all. Same exact set up as before.
Found part of the answer on my wife's Windows 10 computer (which has no java on it):
Clearly, I should copy java.dll somewhere. Think I'll put it in the same directory as everything else (i.e. the same one as the java.exe), and try that.
Nope. Same as before.
So clearly java is looking in the registry to find its .dll.
I've downloaded jre-8u121-windows-x64.tar.gz. I'm going to try the same experiment with that.
Tried the same experiment with java from the tarball above. Exact same symptom. Cannot find java.dll.
Having done a little reading, I see that Embedded Java SE has a way to create custom deployments of java. There appears to be no official analogous mechanism for Java SE for Windows.
Doing a little more reading, I see that there is a mechanism called the Invocation API which can be used to run java, bypassing java.exe. This might be something to try. Might also be time to start surfing the HOTSPOT code.
More on the Invocation API here: http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/invocation.html
An intriguing note I also ran into during my reading said this:
Private vs. public JRE - Installing the JDK installs a private Java SE Runtime Environment (JRE) and optionally a public copy. The private JRE is required to run the tools included with the JDK. It has no registry settings and is contained entirely in a jre directory (typically at C:\Program Files\jdk1.6.0\jre) whose location is known only to the JDK.
I read this here: http://www.oracle.com/technetwork/java/javase/install-windows-142126.html
You might try this experiment with THAT jre.
Today I also face same problem .and I found the solution for this go-to your JDK bin copy path from there and peast this path to environment variable path and the priority should be first that mean it should be peast in starting of all path.
According to the Eclipse FAQ. I read that
Eclipse DOES NOT consult the JAVA_HOME environment variable.
My doubt is how does eclipse initializes the Virtual Machine. It does not know the location of Java. My eclipse.ini file does not have -vm configuration. Still I am able to run eclipse.
The Source
UPDATE
According to Eclipse Installation Guide. Eclipse does not write entries to the Windows registry.
As far as I know, to invoke the JVM, Eclipse executes the java command, so, if it's at your system execution path, Eclipse won't need to find the instalation directory.
To check, you can start a OS shell and execute the next command (from any location):
> java -version
EDIT: I was (partially) wrong. From the FAQ (http://wiki.eclipse.org/FAQ_How_do_I_run_Eclipse%3F#Find_the_JVM)
If a JVM is installed in the eclipse/jre directory, Eclipse will use
it; otherwise the launcher will consult the eclipse.ini file and the
system path variable
So, Eclipse first looks inside its eclipse/jre dir for installed VMs, if empty, consults the eclipse.ini file, and at last, looks at the system path.
Even Help->Installation details->Configuration would give you the exact version and type of jvm you are using . Here it is clearly given in System Properties
Eclipse will run using whatever version of JRE you have installed. To see/edit the version being used, go to Preferences -> Java -> Installed JREs
Or just run a java program in Eclipse. Eclipse will show the full path of javaw command it is using.
Eclipse looks for system Path variable to get the installed JVM. It depends upon how you have defined path variable. Order in which several versions have been defined in path does matter i.e. if jdk1.5/bin is set before jdk1.6/bin, system will pick 1.5 version when you execute java -version on cmd
Solved!
1) downloaded and installed 64-bit versions of both the ADT for Android (Eclipse) and JDK Java bundle
2)updated the PATH environmental variables (Win Control panel...System...advanced opt...Envir.variables)
In my case it now looks like this:
C:\Program\Java\jre7\bin\client\jvm.dll;C:\Program\Java\jdk1.7.0_21\bin
(no backslash after the \bin directory)
These days on WIN64, oracle creates a couple of new directories and adds them to your path. The one eclipse will default to is the second directory you specify in the installation process, because that gets loaded at the head of the path ahead of your JAVA_HOME. It is confusing why they ask you for two directories, I have no answer for that. I blew away the second directory, removed the two added directories from the path, configure my JAVA_HOME environment variable (in my case already on the path pointing to an older version) accordingly, and eclipse is good to go.
Most unix commands whose operation changes based on values of environment variables have a section "ENVIRONMENT VARIABLES" in their man page. No such luck for the java binary (Sun/Oracle Java 6), though I'm fairly certain that things like CLASSPATH and perhaps JVM_OPTS have an effect.
Can anyone point me to a list of environment variables that affect the 'java' binary?
I don't think there are that many, but it will depend on what implementation (oracle vs ibm).
IBM's JDK has a list here: http://publib.boulder.ibm.com/infocenter/javasdk/v5r0/topic/com.ibm.java.doc.diagnostics.50/diag/appendixes/env_var/env_jvm.html
The oracle JDK has, at the very least, CLASSPATH, JAVA_HOME and JRE_HOME. Although in the man page for "java", the only environment variable it mentions is CLASSPATH.
Other tools like ant or tomcat may look for JVM_OPTS, and JBoss uses JAVA_OPTS.
Setting JAVA_HOME to the installation directory and adding $JAVA_HOME/bin to the PATH sould be enough, if you don't have to configure build systems like maven or ant.
CLASSPATH is required on most start scripts to contain the location of supporting libraries (.jar) or third-party stuff.
JAVA_OPTS usualy contains parameters for setting heap-space, debug agent and things like that.
AFAIK java itself does not depend on environment settings, rather start scripts, init services and anything build around.
Thus you won't find a single list of all environment variables related to java (software-products).
There is also _JAVA_OPTIONS, mentioned here, which works for all JVM invocations, including applets and Webstart.
Incomplete answer to my own question:
Oracle has a list for Java 8 of env variables to include when reporting a bug. Not really documentation, and no guarantee it's complete, but it is highly suggestive:
JAVA_HOME
JRE_HOME
JAVA_TOOL_OPTIONS
_JAVA_OPTIONS
CLASSPATH
JAVA_COMPILER
There is specific documentation on JAVA_HOME and JAVA_TOOL_OPTIONS