What environment variables affect the 'java' binary? - java

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

Related

JAVA_HOME path required to be updated after each update of JDK/JRE

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.

Do we need to set Windows environment variables for Java updates anymore?

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.

Build error while installing Clojure in Ubuntu.

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-6-openjdk-i386/jre"
Erm.. But it is pointing to a JDK, open-JDK here. Am I missing out on something here?
Ignore all solutions which suggest adding/setting a JAVA_HOME directory, they are wrong. If you have one set in your .profile etc, remove it.
Ubuntu (and a number of other distros, esp. debian based ones) use an 'alternatives' mechanism to provide a higher level of abstraction to handle things like multiple versions of the same software or multiple sotware packages which provide the same functionality, such as web browsers.
Ubuntu does not require a JAVA_HOME setting, provided you let the OS and it's packaging system manage your environment. If your manually installing things, your then on your own and need to work it out.
I suspect that originally, you only had the JRE installed, you then attempted to fix your problem by adding a JAVA_HOME setting and then later installed the required JDK. If this is the case, remove your JAVA_HOME setting and then use the update-alternatives command to make sure the correct java environment has been setup (see the man page for update-alternatives for details - its very easy).
The advice on using lein is IMO spot on and I would also recommend using the script rather than the packaged version. I would also recommend going witht he 2.0 preview version. It is quite stable and a better place to start than the older 1.x versions.
You could just install leiningen (which is packaged with Ubuntu). This will give you a nice project tool for working with Clojure. It bootstraps and pulls clojure in for you on a per package basis, which will also mean that you have more than one version.
Remove the jre part in the path. That should do the trick.
It would become
"/usr/lib/jvm/java-6-openjdk-i386"
Also as Brian suggested try
sudo apt-get install openjdk-7-jdk

Towards the "true" definition of JAVA_HOME

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.

Difference between JAVA_OPTS and JAVA_TOOL_OPTIONS?

When should each of these environment variables be used?
JAVA_TOOL_OPTIONS is read by some JDK tools, but has limited applicability.
JAVA_OPTS is a convention used by Apache Tomcat and some other apps, but is not
read directly by any JDK tools published by Sun/Oracle, AFAIK.
From:
https://forums.oracle.com/forums/thread.jspa?messageID=6438415
JAVA_OPTS is not an environment variable that the java executable will
recognize on it's own. Instead, various scripts which wrap the start
up of java will often use an environment variable named JAVA_OPTS to
configure the java executable (for example, the tomcat startup script
does this).
see "what is" doc and "tool options" doc
Basically, the JAVA_TOOL_OPTIONS is intended for use by development tools, monitoring tools and the like whereas JAVA_OPTS is used for running 'general' Java programs, I think people tend to mix and match somewhat (from what Google has shown me example wise).

Categories