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

executing jars

 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a straight forward way to execute a jar that references other jar libraries? I'm looking for something that works in the general case so I can repeat this when necessary.

I tried to do it from the console line and with ant, unsuccessfully. Here's what I tried:



in ant:


And this didn't help when creating the jar either



Any suggestions?
 
Paul Clapham
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't tell what that <attribute> element that tries to set the Class-Path of your manifest does, but it looks suspiciously as if it tries to put a library name there. If you want the manifest to refer to other jar files, its Class-Path entry has to be a list of those jar files. Just the name of the directory where those jar files are located isn't good enough. And beyond that you need the relative path from the executable jar to the referred-to jars.

And if you do "java -cp something -jar wotsit.jar", the -cp classpath parameter is ignored. The manifest has to be set up correctly.
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With that then I guess my next question is an ant question: is there any way to have ant add the individual jars to the Class-Path in the manifest?

Am I overlooking an easier way to do this? It seems like a task that ant should be able to do...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15208
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi racarter, please change your name, it is not according to the JavaRanch policy.

When you have code in a JAR, you don't have to run it using the "-jar" option. You can also just put your JAR in the classpath and specify the class name of the main class on the command line. If you do it like that, Java doesn't tie you to the Class-Path attribute in the manifest file in your JAR file:

java -cp lib1.jar;otherlib.jar;myjar.jar com.racarter.MyMainClass
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic