Setting classpath in Linux

I’ve previously used Java only in Windows but am now trying to use it in Linux. I’m having trouble setting up the blessed classpath. Can anyone help please?
I have installed Java SDK as root in /opt/j2sdk1.4.2_10/ as was the default.
THis is how I have set the classpath so far -
CLASSPATH=/opt/j2sdk1.4.2_10/bin:/opt/j2sdk1.4.2_10/lib/tools.jar
I am trying to compile a test program javac HelloWorld.java as a non root user from home/java/ but always get -
bash: javac: command not found
I’ve tried variious alternative commands but still the same. Is there something obvious I’ve got wrong?

Thanks for any help.

Lagoona

In your home directory (the directory you’re in when you log in, probably /home/<username>) there should be a .config file, use ls -a to see it.

Open it in an editor.

add a line somewhere that looks something like this:

export CLASSPATH=$CLASSPATH:<stuff you want to add to the classpath>

this way you won’t overwrite the existing classpath

save, exit, and enter:
source .config
or logout and back in

Are you running on a multi user server or a local machine (or server you have full control over)?

Thanks. I haven’t got a .config file. I’m using Fedora 2.4.
Should I use the file .bashrc instead, which is there?

Lagoona

I’m using a local machine I have full use over.

Lagoona

Here are the instructions I followed last time I did it (been a while) and it worked fine:

Java Development Environment:

Download the Java 2 SDK 1.4.2. The self-extracting file has to be made executable before it can be run:

chmod +x j2sdk-1_4_2_05-linux-i586.bin

As root, copy it to /usr/local and run it:

su -
cp j2sdk-1_4_2_05-linux-i586.bin /usr/local
cd /usr/local
./j2sdk-1_4_2_05-linux-i586.bin
rm j2sdk-1_4_2_05-linux-i586.bin

[B]Set up the environment by creating the file /etc/profile.d/java.sh with the following content:

JAVA_HOME=/usr/local/j2sdk1.4.2_05
JDK_HOME=$JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH

CLASSPATH=.:/usr/local/j2sdk1.4.2_05/jre/lib/rt.jar

for i in /usr/share/java/*.jar ; do
CLASSPATH=$i:$CLASSPATH
done

export CLASSPATH PATH JDK_HOME JAVA_HOME[/B]

Make the java.sh script executable (“chmod +x /etc/profile.d/java.sh”). After logging out and back in, verify that everything is set up correctly:

java -version
echo $CLASSPATH

Thankyou so much dc dalton,

This worked perfectly. My sdk is in the opt directory, so this is what my java.sh looks like

JAVA_HOME=/opt/j2sdk1.4.2_10
JDK_HOME=$JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:/opt/j2sdk1.4.2_10/jre/lib/rt.jar

for i in /usr/share/java/*.jar ; do
CLASSPATH=$i:$CLASSPATH
done

export CLASSPATH PATH JDK_HOME JAVA_HOME

Lagoona

Glad I could help.