Note that java dumps this listing to stderr rather than stdout, so the usual pipe through more will not
have the desired effect. You are going to have to either scroll or, on linux-based systems, redirect
error output to a file and then grep through that.
Are You, or Do You Know, a Friendly Java Programmer?
The value needed is the value of the java.home property, which is available from inside a java
executable if you know what you are doing. A java programmer should be able to write a reasonably
short program to print this value for you on demand, so you never have to bother him or her again.
I'm not a java programmer, so if you happen to have a program like this you'd like to donate to the
cause, please get in touch.
Alternately, if you have the privileges you can update your java installation to the most recent version
and use the "Java Version 1.7 or later" method, above.
Are You Ready to Do It the Hard Way?
As a last resort, you'll have to dig through system directories, trying to find the java installation files.
This can be tricky, since the installation might be for the Java Developers Kit (look for directories
starting with "jdk"), or the Java Runtime Environment (look for directories starting with "jre"), or it
might be referenced as the Java Virtual Machine (look for directories starting with "jvm").
Search functions are your friend, here. On Windows machines, first look for a "Java/ directory in your
"Program Files", "Program Files (x86)" or equivalent system directory. If you find one, look down into it
until you find the subdirectory containing the bin/ and lib/ directories. If that fails, try searching for
the java executable itself, and use the name of the directory that contains the bin/ directory that, in
turn, contains the java executable.
On linux-based systems, where there is much greater scope for variability, try running
the find command on directories like /usr/lib or /usr/share. (You should have permission to read any
directories that might contain java libraries you'd reference, so you can ignore "Permission denied"
messages.)
Setting JAVA_HOME
The JAVA_HOME environment variable can be set temporarily, so that when a script or batch file
finishes, or you close your command window, it goes away; or as part of your regular environment.
The syntax is roughly the same either way, but where you set the value changes.
On Windows Systems
To set the value temporarily from the command line, use the set command:
C:>set JAVA_HOME="C:\Program Files (x86)\Java\jre"
where spacing and capitalization count, and everything inside the quotes should be replaced with
the path you found via one of the methods in the previous section. The double quotes are required if
your path contains any imbedded blanks.
To create and set a JAVA_HOME variable as part of the default environment, use the method
appropriate to your particular flavor of Windows described here:
•
How to set the path and environment variables in Windows, by ComputerHope.com
Then insert the path you found previously.