It's not a secret anymore!
The moose likes Beginning Java and the fly likes Classpath - usual problem I guess Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classpath - usual problem I guess" Watch "Classpath - usual problem I guess" New topic

Classpath - usual problem I guess

Micky Pat

Joined: May 03, 2006
Posts: 18
Hi guys,

I hope you can help me.
Some time ago I wrote an application to download some stuff from the web and do something with that: since I needed functionalities provided in external packages, I unzipped those binaries and jarred them up together with my classes, getting a monolitic jar with my and external functionalities.
Now, apparently a much better way of doing this is jarring just my stuff, and running this jar using "classpath" to refer to external jars...

So, I created my slimmed "myJar.jar" in C:\ and the external ones in C:\lib\, and I am trying to run this using a Command Prompt in Windows XP BUT... I can't find a way of specifying the classpath.
The command I am trying to run is:

java -classpath C:\lib\A.jar;C:\lib\B.jar -jar myJar.jar

I googled quite a lot, I found different versions about the use of single or double quotes around the imported jars, another site suggested to specify the Class-Path in the MANIFEST contained in myJar.jar (looks a bad solution though, given that if I change the location of the external jars in the future I will need to update the MANIFEST as well)...

Any suggestion? Please help me, I am desperate and this is probably a trivial problem....

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

When you use the "-jar" option, then the "-classpath" parameter is ignored and the classpath comes from the Class-Path entry in the jar's manifest. I assume you already read about that, since that other site told you about it. Your objection about not liking that idea because you might move the dependent jars is just lame. Put them in the same directory as your executable jar, so it's easy to specify Class-Path, and don't move them.
Micky Pat

Joined: May 03, 2006
Posts: 18

Thank you Paul
I agree. Here's the link:
subject: Classpath - usual problem I guess
It's not a secret anymore!