• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Executable jar that contains other jars

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello!


How can I create a app.jar that contains jarlib1.jar jarlib2.jar...
In the manifest file I have:
This is working, but I have to copy all dependent jars in the app.jar's folder.


How can I create a app.jar that contains all dependent jars and can be executed with:
java -jar app.jar
?


Regards
 
Marshal
Posts: 79973
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anything helpful in the Java Tutorials? Look in the section about updating jars. Does that help?
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is working, but I have to copy all dependent jars in the app.jar's folder.



Well,. that's how the manifest tag works... it doesn't magically copy all the jars into one big jar. It just defines what jar files to look for.

If you want one big jar, you will have to do it youself -- extract all the jars into one location for classes, and jar the whole wad back together. Personally, I would not recommend doing this. What is wrong with having separate jar files?

Henry
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your answers!


And is there any chance to do this with Maven or any OneJar app?

I am looking around, but still haven't find any working solution. It's more elegant to have only one app.jar file, than to have app.jar file and additional lib folder.
I'm also thinking about obfuscating code later...


Regards
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Imre Tokai wrote:Thank you for your answers!


And is there any chance to do this with Maven or any OneJar app?

I am looking around, but still haven't find any working solution. It's more elegant to have only one app.jar file, than to have app.jar file and additional lib folder.
I'm also thinking about obfuscating code later...


Regards


Take a look at the Maven Maven Assembly Plugin. Specifically you will want to look at the jar-with-dependencies Predefined Assembly Descriptor. The usage page has some discussion on it.

Java 7 is going to be introducing the concept of a Java Module (JAM) -- see JSR 277 -- which will basically deal with this as well. A JAM will apparently be a super-set of JARs. So you'll put your JARs in your JAM rather than your jam in jars like Smuckers does ;)
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
intermediate level
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I used Maven and created one-jar successfully!

But i haven't had success without Maven.
In manifest file i added
Main-Class: package1.Mainclassname
Class-Path: lib/jar1.jar lib/jar2.jar...
and copied necessary jars to the lib folder (which is in the same folder where app.jar is).
Jars are not recognized.

How can I create one-jar without Maven?


Regards
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

What is the error message you are getting when you try to run it?

The manifest information you are showing looks good. Try doing a diff between the manifest you are creating and the one Maven created. See if anything jumps out. One thing to note is when you wrap an entry onto the next line (after 70 characters), you need a space at the start of that next line. For example:


Notice the spaces at the start of lines 4, 8, & 9.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic