Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting multiple jar file when running Java Class from Linux

 
Ajoo Bar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20763
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48418
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic