Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath - usual problem I guess

 
Micky Pat
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21314
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thank you Paul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic