File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath for jar files (Tiger)

 
Sreedevi Vinod
Ranch Hand
Posts: 117
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm preparing for the new SCJP5.0 tiger exam which is going to be released. Suppose I have my clases in multiple jar files, is it possible to set the classpath to *.jar ? When I had just one jar, and I set the classpath to *.jar when I ran javac it worked fine. But it didn't work when I used 2 jar files.
Any thoughts on this ?

Thanks
Devi
 
Joyce Lee
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Devi,

Suppose I have my clases in multiple jar files, is it possible to set the classpath to *.jar ?

Multiple jar files can be included in the classpath using the following command:



However, using wildcard to specify multiple jar files like the one below is not possible.



When I had just one jar, and I set the classpath to *.jar when I ran javac it worked fine. But it didn't work when I used 2 jar files.

It'd be helpful if you could show us the exact commands you ran.

For more info on setting the classpath, check out "Setting the Classpath" under General Information section.

Joyce
[ April 04, 2005: Message edited by: Joyce Lee ]
 
Sreedevi Vinod
Ranch Hand
Posts: 117
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Joyce

I had just one jar file which contained a class used by Test.java
This is the exact command I gave
javac -classpath *.jar Test.java
However, when I put one more jar file in the same folder and tried the command it did not work.

You are right. I have seen the link which talks about classpaths. There is no mention of the *.jars command. But do try the above in a windows machine and do let me know.

Thanks
Devi
 
Joyce Lee
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right, Devi. With one jar file in the current directory, the classpath can be set to *.jar (I'm using JDK 5.0 on win2000). I wasn't able to reproduce the scenario you mentioned initially because I placed two jar files in the directory. This seems like a bug to me because according to the classpath doc, it says,

Each classpath should end with a filename or directory depending on what you are setting the class path to:
...
For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.


Furthermore, it doesn't make any sense to use wildcard, i.e. *.jar, when only one jar is allowed in the directory. What do you think?

Have you tried running it using "java -classpath .;*.jar Test"? It doesn't work. It only works if the name of the jar file is specified, like this "java -classpath .;pkg.jar Test". It seems like "java" behaves correctly according to the classpath doc.

Joyce
[ April 05, 2005: Message edited by: Joyce Lee ]
 
Senthil B Kumar
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i make a Single Jar file,which will contain the multiple jar files.

Say Total.jar which will contain A.jar and B.jar.

Now can i give Total.jar in classpath ? instead of individually giving A.jar and B.jar in classpath ?
 
Joyce Lee
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Senthil,

Now can i give Total.jar in classpath ? instead of individually giving A.jar and B.jar in classpath ?

If there're classes in A.jar and B.jar on which Test.java depends, then no, the classpath cannot be set to Total.jar like the one below:


Joyce
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic