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.

Setting path for java variable in terminal environment

installing and downloading sun java package
1. download the package jdk-6u29-linux-i586.bin
2. type the following to extract

        sh jdk-6u29-linux-i586.bin

   which will extract it in the current directory
3. Move extracted folder to the location /usr/lib/jvm

        sudo mv jdk1.7.0_ /usr/lib/jvm/

4.Inform Linux/ubuntu that new java source is available by typing (instead of editing in .bashrc file)

        sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_/bin/javac 1

  this installs the javac compiler and for the java interpreter type the below one

        sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_/bin/java 1

5. now after installing configures required for it type

        sudo update-alternatives --config javac

        sudo update-alternatives --config java

Thursday, August 9, 2012

how to introduce new variable, add path to script in linux environments using a console

adding a new path in console,

export  PATH=$PATH:/home/commands

this command with append the new path /home/commands to the environment, where, the console program check in the newly path for the commands, if commands are not found in the exsisting paths.

adding a new variable in console,


export  cd=/home/jai

 this creates a new variable next with value /home/jai . when cd is used along with the newly defined variable, it changes current directory to one /home/jai . 

cd $next
 
this  one changes the current directory to new one.


export
keyword/in-built console variable is used along with others because it make it possible to introduce a new variable or define paths at every time when the console open, hence export declares the definitions as global declarations

How to extract a bin file within linux using terminal

copy the bin file to the location u want.

 cp  /path/filenam.bin  /path_u_want/

now after copied , change into the directory. Two ways to extract bin files.
firstly,  type 

sh  filenam.bin  

the filenam.bin(binary file) is extracted.
               or

change the permission of bin files by typing 

chmod -c 777 filenam.bin 

now run the bin file by typing

./filename.bin  
  
or 

filename.bin 

this will extract the binary files into a folder with name of binary file.

Setting path for new script file from an package within console

here, path for a script file within an extracted folder are set, without editing .bashrc file. u can choose any path for ur script file.

now for installing or for introducing the script file to console environment, type

sudo update-alternatives --install /usr/bin/scriptfilenam scriptfilenam /path/scriptfilenam



scriptfilenam - name of script file,  path - path of script file(eg: /home/play-2.0.2/)
" update-alternatives  - maintain symbolic links determining default commands
   update-alternatives creates, removes, maintains and  displays information  about  the symbolic links comprising the Debian alternatives system. "
 
says the manual page for update-alternatives.

install option , adds the alternative link of script file to the console environment.
now again type


sudo update-alternatives --config scriptfilenam

 which configures  this file.


hence, new scripts path is set. check it by typing the scriptname