Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delivering a single jar with a Maven project

Tags:

maven-2

jar

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?

like image 790
Gonzalo Garcia Lasurtegui Avatar asked Oct 06 '10 14:10

Gonzalo Garcia Lasurtegui


People also ask

How do I package a Maven project into a jar?

In order to compile the project into an executable jar, please run Maven with mvn clean package command.

How do I deliver a Maven project?

Normally when I deliver a maven project to a client, I just do a "mvn clean" followed by a zip-and-ship of the cleaned project directory. If my project is self-contained (and ideally it is), that's all the recipient needs.


1 Answers

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

  • with the Maven Assembly Plugin and maybe the jar-with-dependencies predefined assembly descriptor (that will unpack dependencies)
  • with the Maven Shade Plugin (similar to the above one but gives more flexibility)
  • with the Maven One-Jar Plugin (that uses One-JAR and its custom classloader to allow nesting of JARs)

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

like image 145
Pascal Thivent Avatar answered Sep 24 '22 20:09

Pascal Thivent