File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes PATH, JAVA_HOME and JRE_HOME best practices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "PATH, JAVA_HOME and JRE_HOME best practices " Watch "PATH, JAVA_HOME and JRE_HOME best practices " New topic

PATH, JAVA_HOME and JRE_HOME best practices

Jim Smithian

Joined: Sep 21, 2004
Posts: 18
Java applications usually start by batch files or shell scripts which among other things set the executable java from the JRE_HOME or JAVA_HOME or the PATH environment variables. What are the best practices in writing such scripts and setting the PATH and JRE_HOME and JAVA_HOME considering the following factors:

-convenience for average end users
-multiple versions of JRE/JDK in the same machine

Should we find 'java' from the PATH, JRE_HOME or JAVA_HOME?

Is there any good online resources about these?

Thanks for your comments.

Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265


Good question. We usually use JAVA_HOME.

More important than what you pick is that you document it in an easy way for your users to find out and know what to set if they haven't already!

There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

JAVA_HOME should be set to the home folder of your JDK - typically C:\jdk1.6.0_05 (or whatever version and wherever you installed it).

JRE_HOME is hardly ever needed - I've never ever set it before.

PATH should include "%JAVA_HOME%\bin" for Windows or $JAVA_HOME/bin for Linux / Unix / ...
Depending on whether or not JAVA_HOME contains any spaces you'd want to put the entire path, including the \bin, in quotes.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: PATH, JAVA_HOME and JRE_HOME best practices
jQuery in Action, 3rd edition