Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

executing jars

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28128
94
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic