Thursday 2 December 2010

How to set the Java Classpath

In Windows 7:
Control Panel->System->advanced system settings->environment variables->system variables:
Create new variables:
->click new
variable name: CLASSPATH, variable value: C:\Program Files\Java\jdk1.6.0_22
variable name: JAVA_HOME, variable value: C:\Program Files\Java\jdk1.6.0_22
variable name: Path, variable value: ...;...;C:\Program Files\Java\jdk1.6.0_22\bin; (append it to the existing path, don't forget the semi-columns(;))

2 comments:

javin paul said...

Hi,

Its worth noting that if you have two classes with same name in classpath in that case one which comes earlier in classpath will get picked up. this concept is very useful to test patch releases where you update only few classes to quickly test patch release or have added some debug print statement to troubleshoot any issue. to read more about How classpath works in Java

Thanks
Javin
FIX Protocol Interview Questions

asianuxxx said...

On Linux, I simply add a few lines to the .bashrc file in my home folder, so that's set up when the shell starts. Something like: export CLASSPATH=${CLASSPATH}:/dir/dir/whatIwantToAdd. Since it is hidden by default, you'll have to find the file using "ls -a".