tags:

views:

39

answers:

3

I want to deliver a single .jar file to my clients, but my project is currently built with Maven, and I have several modules that generate a single .jar each.

I know nesting different .jar files is not a great idea, so I am not sure how can I achieve this.

Any ideas?

+1  A: 

Actually, nesting .jar files is not possible. A jar can't have other jars in it.

.war and .ear files can contain jars, and that's a good solution if you're delivering a J2EE application.

If your app is just J2SE, however, I recommend looking at the Maven Assembly plugin. As the name implies, it allows you to create a single binary distribution of your build.

RonU
+3  A: 

First of all, ask yourself if you have a really good reason for packaging your application and all of its dependencies in to a single jar. I haven't found a very many good reason for this at all (with most reasons being related to organizational policy foolishness or just plain ignorance). The way to go is to keep libraries in their own jars and supplying a .zip/.tar.gz containing all of your libraries and your application with either

  1. An executable .jar with the classpath setup appropriately in your MANFIEST.MF file
  2. a .bat/.sh script that invokes java and builds an appropriate classpath based on your deps

Conversely, use JNLP (better known as Java Web Start).

If you really want to have maven bundle all of your dependencies and your application under a single jar, what you want to use is the "jar-with-dependencies" predefined assembly. The maven assembly plugin usage page also shows how you might this up as well.

whaley
Thanks for the reply. I am delivering a Web Service API for a client, actually to make the life easier for our Java clients, we want to deliver a single .jar - they can also generate the code from the WSDL. This is not uncommon in some Google Web Services.
Anonimo
+2  A: 

If you really want to go this direction, there are several ways to do that:

Depending on your exact requirements and constraints, you might prefer one or the other.

Pascal Thivent