Himanshu Matta
Himanshu Matta

Reputation: 73

Set classpath permanently in Linux

I am using centos and I have 4 to 5 jar files which I want to add permanently in classpath, So that I can run my program from anywhere. I tried this-

 export CLASSPATH="/path/to/file:/path/to/file2"

Above command worked perfectly but I think it was not adding files permanently. When I opened new tab and tried to compile my program then I was getting same error i.e jar files were missing.

Now, Please help me to add these jar files permanently to classpath.

Upvotes: 2

Views: 8940

Answers (2)

Rahul R Dhobi
Rahul R Dhobi

Reputation: 5806

Add your path to /etc/profile and reboot to take effect

export CLASSPATH="/path/to/file:/path/to/file2"

Upvotes: 1

Lee Duhem
Lee Duhem

Reputation: 15121

You could add that export statement to the end of your bash init file ~/.bashrc, therefore it will in effect all the time.

By the way, a better setting of CLASSPATH would be

export CLASSPATH="/path/to/file":"/path/to/file2":"${CLASSPATH}"

this will also preserve the initial value of that environment variable.

Upvotes: 2

Related Questions