Monday 15 June 2015

How and where to set CLASSPATH for java in Ubuntu

For beginners of Java and Ubuntu, setting up CLASSPATH can be tricky. There are plenty of posts already on Stackoverflow for these, which provides detailed and multiple answers to many questions. But I found them all scattered over multiple question. Here I have compiled those simple steps. I hope you will be able to run the program without errors after this.

If you have successfully installed java, then follow these steps:

1. First step is to find the current version of java. In the terminal, type
 java -version 
. You must be getting your version something like this depending on : java version "1.7.0_79" .

Now from terminal type:
 
cd /usr/lib/jvm 


Now type ls and check the name of the folder. Mine was java-1.7.0-openjdk-amd64.

Now decide where will you store your java applications.
I had /home/jeni/Documents/javaProg

The CLASSPATH will be set in /etc/environment. In terminal type:
 sudo gedit /etc/environment 
. At the end of the file, add the following lines:

 
JAVA_HOME="/usr/lib/jvm/java-7-openjdk-i386/bin"

   export JAVA_HOME

   CLASSPATH=".:/usr/lib/jvm/java-7-openjdk-i386/lib:/home/laptop/Desktop/a2"

    export CLASSPATH

  
After this you can compile and run your program. If you find this article useful or have any problems, please let me know your reviews.  

No comments:

Post a Comment

Powered by Blogger.