Originally posted by Hardik Raja:
OK I got what you explained...
but If I am including some directory path
eg. c:\hardik (note hardik is a directory) in PATH environment variable
and hardik contains one package p1 which contains a class file animal
i.e p1.animal which I require in test.class
If I exceute using java test...it give the following runtime error..
Exception in thread "main" java.lang.NoClassDefFoundError: p1/animal
at p2.test.main(test.java:9)
and If I execute using overriding classpath say....
java -cp \hardik;. test
..It Executes perfectly..
Why is the default classpath not able to find animal class(p1.animal) ?
Thanks
JAVA_HOME is used to store the directory where you installed java (so you don't have to hardcode the actual locations into your scripts and also so other programs can find the location of the JVM.
The PATH and CLASSPATH variables are not the same.
You set the PATH environment variable to tell the operating system where to find the java and javac commands. Typically this is JAVA_HOME\bin. If you dont do this you will see an error
'java' is not recognized as an internal or external command, operable program or batch file.
You set the CLASSPATH environment variable to tell the java javac commands where your classes and packages are stored. ie CLASSPATH="c:\hardik;."
The . means that it also looks in the current working directory for classes and packages.