File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jar file creation using Maven

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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 Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought of doing it with Assemblies in Maven. Any idea from that front?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want a jar that contains other jars?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • 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 Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the responses!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic