Codes from my life

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.

Advertisements

Comments on: "Setting CLASSPATH for Java in Linux" (1)

  1. Hi,

    Its worth noting that if you have two classes with same name in classpath in that case one which comes earlier in classpath will get picked up. this concept is very useful to test patch releases where you update only few classes to quickly test patch release or have added some debug print statement to troubleshoot any issue. to read more about How classpath works in Java

    Thanks
    Javin
    Why String is immutable in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: