Pages

Wednesday, August 15, 2012

Setting Class path for the Java classes(jar packages) in java environment using terminal

installing and downloading junit.jar file
1. download junit-4.10.jar file
2. copy the jar file to the location /usr/share/java/
3. now open a terminal and type to change to your user directory

          cd

4. now find the location of .bashrc file

          locate .bashrc

   it may display 3 or 4 results, out of it choose only '.bashrc' file in the user home directory
5. after locating it, open the .bashrc file

          vim .bashrc

6. now add the current line to your file  and save and exit from the terminal

          export CLASSPATH=$CLASSPATH:/usr/share/java/junit-4.10.jar;.;
               or
          export JUNIT_HOME=/usr/share/java

          export CLASSPATH=$CLASSPATH:$JUNIT_HOME/junit-4.10.jar;.;

7. to check whether path is set, open a terminal and  type

          echo $ CLASSPATH

    it displays the result as below

          :/usr/share/java/junit-4.10.jar

8. u can also verify it by typing in the terminal
   
          java junit.textui.TestRunner
  
   the above command display like below
  
          Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class
  
   or if it display like below, then path is not set properly

          Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/TestRunner
           Caused by: java.lang.ClassNotFoundException: junit.textui.TestRunner
              at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
           Could not find the main class: junit.textui.TestRunner.  Program will exit.

No comments:

Post a Comment