wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Classpath for jar files (Tiger) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Classpath for jar files (Tiger)" Watch "Classpath for jar files (Tiger)" New topic
Author

Classpath for jar files (Tiger)

Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
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

Joined: Jul 11, 2003
Posts: 1392
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

Joined: Jan 17, 2005
Posts: 117
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

Joined: Jul 11, 2003
Posts: 1392
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

Joined: Feb 09, 2004
Posts: 140
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 ?


Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
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
 
subject: Classpath for jar files (Tiger)
 
Similar Threads
struts application deployment in tomcat server
Spring 3.0.6 classpath issue.
how to define jars in classpath
Using j2ee packages
classpath to jar files in a folder