java environmental variables

Z

zxg_32

Hi, there.

Many sources talk about setting/updating PATH, JAVA_HOME, CLASSPATH
environmental variables after JDK installation. PATH is easy to
understand. CLASSPATH is actually not recommended by SUN:
http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html

My question is about JAVA_HOME, what is it used for? Is PATH (maybe
plus CLASSPATH) enough? I tried compiling and running a java program
without setting JAVA_HOME and CLASSPATH (PATH is set), and it works
fine. Is JAVA_HOME just redundant?

Thanks.

P.S. I know Tomcat needs JAVA_HOME to work properly, what else?
 
H

Harry Bosch

Here is a good explanation of classpath (Roedy Green's Famous Java
Glossary Website)
http://mindprod.com/jgloss/classpath.html

There are several reasons to have a JAVA_HOME variable set up, here are
a couple.


1) You may have several versions of java installed on a machine, and
you can specifically state which java version you want to use. Then,
by having your $JAVA_HOME/bin directory in your path, you can
dynamically change JAVA_HOME to whatever version of java you want to
use without having to much with your PATH variable.

2) Applicaitons such Tomcat may want to know exactly where specific
java runtime files, and perhaps some tools (in the tools.jar for most
OSs) are. So, that is why it looks for the JAVA_HOME variable.

As for CLASSPATH

Setting up a specific CLASSPATH variable within your environment
(shell, or windows environment) can be really nasty. You usually want
to set this up explicitly in your startup scripts (or manifest in your
jar files). If you have a classpath set for your environment, you can
really run into some strange and confusing errors because you may end
up having versioning issues if your app is expecting a newer version of
a class, and an older one is on your CLASSPATH. So, just be careful to
check if you have a classpath set up and reset it for your needs.

Harry Bosch
 
H

Hemal Pandya

Harry said:
Here is a good explanation of classpath (Roedy Green's Famous Java
Glossary Website)
http://mindprod.com/jgloss/classpath.html

There are several reasons to have a JAVA_HOME variable set up, here are
a couple.


1) You may have several versions of java installed on a machine, and
you can specifically state which java version you want to use. Then,
by having your $JAVA_HOME/bin directory in your path, you can
dynamically change JAVA_HOME to whatever version of java you want to
use without having to much with your PATH variable.
This is not true. If you include $JAVA_HOME/bin in path and then change
JAVA_HOME the change will not be reflected in your path. Not any any
shell/command interpreter I know. This is the reasons scripts invoke
java as ${JAVA_HOME}/bin/java. Then your changes to JAVA_HOME have
effect,

Even if JAVA_HOME is not set, java sets the property "java.home" to the
parent directory of java executable.
 
D

Dirk Michaelsen

Hi,
This is not true. If you include $JAVA_HOME/bin in path and then change
JAVA_HOME the change will not be reflected in your path. Not any any
shell/command interpreter I know.

well, this works just fine here (on Windows) ;-)

All you have to do is to close and reopen the command line window
after changing the JAVA_HOME environment variable. Thats all.

cu
Dirk
 
H

Hemal Pandya

Hi,


well, this works just fine here (on Windows) ;-)

All you have to do is to close and reopen the command line window
after changing the JAVA_HOME environment variable. Thats all.

hmmm. Didn't think of it. Right, so scripts the directly reference the
java executable /will/ use the one referred to by current value of
JAVA_HOME.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top