GeeCON Prague 2014*
The moose likes Java in General and the fly likes setting multiple jar file when running Java Class from Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "setting multiple jar file when running Java Class from Linux" Watch "setting multiple jar file when running Java Class from Linux" New topic
Author

setting multiple jar file when running Java Class from Linux

Ajoo Bar
Ranch Hand

Joined: Mar 28, 2011
Posts: 30
I am running a stand alone java class on a linux prompt, the java class has reference to 2 different classes in jar file
I am running this command

java -classpath /local/home/test/lib/commons-httpclient.jar:commons-logging.jar:. TestClass

I am running this command from the directory where I have TestClass. But it is not finding a class which is in commons-logging.jar

ANy help will really be appriciated
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

That would mean that commons-logging.jar is not in your current working directory. Perhaps it's in the same directory as commons-httpclient.jar? If so, then you should say that in your classpath.
Nishanth Thomas
Greenhorn

Joined: Sep 08, 2011
Posts: 7

By Nishanth Thomas ISG Bangalore

try this
First check your class path
by

echo $CLASSPATH
if not set

CLASSPATH=".:/usr/java/jdk1.6.0_05/bin"

and complie like this which takes all jar in the folder or give path

javac -cp :\* test.java

then run
java -cp :\* test

Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
Nishanth Thomas wrote:
if not set

CLASSPATH=".:/usr/java/jdk1.6.0_05/bin"

and complie like this which takes all jar in the folder or give path

javac -cp :\* test.java

then run
java -cp :\* test


There are two things wrong with this
1. The JDK bin directory does not contain any jar files or classes so does not need to be in the CLASSPATH. You probably do need it in your PATH environment variable.
2. There is no point in setting a CLASSPATH environment variable if you are going to use the -cp option, as this will cause the environment variable to be ignored.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39070
    
  23
In fact, setting a system classpath usually does more harm than good. I recommend, as well as following SB’s good advice, you delete that classpath as being completely unnecessary.
 
GeeCON Prague 2014
 
subject: setting multiple jar file when running Java Class from Linux