• 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

Jar file creation using Maven

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

I have a simple class file with a main method. I would like to now create a jar file using Maven which also has all the jar's that it uses. I have even set up the Maven project and when I actually built it, it creates a jar file but I do not find any referenced libraries as part of that jar. How to acheive this?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if the jar contained the other jars it's still not going to work like you think it will; you'd either need to include all the classes from the dependencies in the jar (i.e., unzip then add to the distribution jar's class directory hierarchy) or create a zip file distro which can be unzipped and run with the appropriate classpath set.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought of doing it with Assemblies in Maven. Any idea from that front?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you want a jar that contains other jars?
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Why do you want a jar that contains other jars?



Maybe to make an executable jar that depends on library jars without having to explode them and merge them into the main jar classes?

There is, BTW a Maven plug-in to do exactly that. It's called something original like "Maven Executable JAR plugin" and its targets include both a jar that can be executed via the "java -jar" command and a more traditional JAR that can be included in a classpath.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does referencing bundled jars in the manifest work? I guess I didn't know you could do that without using shade--I thought referenced libs had to be external to the jar being executed.

In any case:

http://maven.apache.org/plugins/maven-jar-plugin/

Specifically:

http://maven.apache.org/shared/maven-archiver/examples/classpath.html

For shading:

http://maven.apache.org/plugins/maven-shade-plugin/index.html

(Very handy sometimes.)
 
Tim Holloway
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think this is shade:

http://maven.apache.org/shared/maven-archiver/examples/classpath.html

And, if I understand the question correctly, yes, dependencies get included in the executable version of the jar, according to the usual scope rules.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the responses!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic