Setting the JAVA_HOME environment variable
Many Java programs launched from batch files, such as Ant and Cocoon, check for
the JAVA_HOME environment variable. If it is missing, the program may not
start, or it may display a message such as
Warning: JAVA_HOME environment variable is not set.
How do I check whether JAVA_HOME exists?
If you are not sure the variable exists,
you can easily check on Windows. Runset > vystup.txt or simply set
at the command prompt (Start >> Run >> cmd). In the first case,
the output is written to vystup.txt, and in the second it is printed
on the screen. If the variable exists, it will appear in output
like the following:
[In this example output, identifiers and network paths have been replaced with fictional examples.]
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\example-user\Application Data
COMMANDER_PATH=C:\Tools\TotalCommander
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=EXAMPLE-WORKSTATION
ComSpec=C:\WINNT\system32\cmd.exe
HOMEDRIVE=H:
HOMEPATH=\\example.invalid\example-share\example-user
JAVA_HOME=c:\tools\Java\j2sdk1.4.2_02Where should JAVA_HOME point?
JAVA_HOME must point to the directory where
Java is installed. That directory directly contains the bin and lib directories.
If Java is installed in c:\tools\Java\j2sdk1.4.2_02 (and c:\tools\Java\j2sdk1.4.2_02\bin and c:\tools\Java\j2sdk1.4.2_02\lib exist),
set JAVA_HOME to c:\tools\Java\j2sdk1.4.2_02.
Where do I set JAVA_HOME?
The simplest and somewhat laborious way is to add a line to the startup batch file:set JAVA_HOME=adresář Javy, for example JAVA_HOME=c:\tools\Java\j2sdk1.4.2_02. A more
elegant option is to set JAVA_HOME as an environment variable
as follows on Windows:
My Computer >> System Properties >> Advanced >> Environment Variables
In the Environment Variables window you have two choices. A user variable applies
only to one user, and a system variable is visible to all users.
I recommend creating a system variable and restarting
the computer afterward.
Related articles
Related CZ Podcast episodes
- #3 · Java 6 SE, Vývoj webových aplikací
Dagi and Filemon discuss Java 6 and web application frameworks. · Czech audio
- #1 · Vývojová prostředí v Javě
The first CZ Podcast episode looks at Java development environments. · Czech audio