Codes from my life

Posts tagged ‘CLASSPATH in Java’

Setting CLASSPATH for Java in Linux

This was really tough for me since I had never used command line for compiling java programs, I always used Netbeans for coding in Java. Recently I started learning JUnit for which I decided to use command Line.

Whenever I googled for its solution I got
$ export CLASSPATH=$CLASSPATH:

But this did not fix my problem. Eventually I landed up on some websites and finally here. Though it is mainly written for Windows but can be used likewise for linux also.

So the thing to be done is either add all the jar files explicitly to the classpath or put all the jars in a directory (/home/roshan/jars for me).

Now run this command:
$ export CLASSPATH=$CLASSPATH:/home/roshan/jars/*

The wildcard ‘*’ fixed the problem. Now you can make this change permanent by adding this command to your .bash_profile in home directory or /etc/profile to make system wide changes.