Tuesday, October 28, 2008

How do I set my java classpath?

How do I set my java classpath?

Problem

Linux uses Red Hats java package instead of the Sun jdk.

Reason

The java interpreter from the standard Red Hat installation is placed in /usr/bin, which is in the path where Linux search for executables. This will be used be default if you don't specify otherwise.

To find the java classes, you also have to set the java classpath to point to the java kit you want to use.

Solution

Set your PATH and CLASSPATH environment variables to reflect which java kit you want to use.

In the ITU Linux machines in 2003, the following java kits are installed: jdk1.3.1 and j2sdk1.4.1. They are placed in /usr/java.

To use jdk1.3.1, add the following lines to the file ".bashrc" in your home directory:

export PATH=/usr/java/jdk1.3.1/bin:$PATH
export JAVA_HOME="/usr/java/jdk1.3.1"
export CLASSPATH=.:/usr/java/jdk1.3.1

If you want to use the j2sdk1.4.1, replace jdk1.3.1 with j2sdk1.4.1 and it should work.

No comments: