2

I created a simple Maven project (Packaging type - Jar) that has dependencies on Spring and My Sql library (mysql-connector). When I package this project with $mvn package I do get a jar file after successful execution of this command.

I was also trying to include all the dependencies in the output jar file, so I added a 'jar-with-dependencies' assembly descriptor, but as the documentation says:

The `jar-with-dependencies` descriptor builds a JAR archive with the contents of the main project jar along with the unpacked contents of all the project’s runtime dependencies. 

I want to include the dependencies in JAR form, not the unpacked way. How can I do this?

Jared
  • 1,887
  • 3
  • 20
  • 45
Vicky
  • 5,380
  • 18
  • 60
  • 83

3 Answers3

4

Java cannot load classes from jars in your jar out of the box. You must configure it with project like one-jar and maven plugin.

amra
  • 16,125
  • 7
  • 50
  • 47
2

Maybe this can help Maven Shade Plugin:Maven Excecutable Jar

Olivier

Mohammad Dehghan
  • 17,853
  • 3
  • 55
  • 72
Olivier Lamy
  • 2,280
  • 1
  • 14
  • 12
0

Vicky is trying to aggregate the jars and this is known as "building-an-aggregate-jar" in Maven's terms. You can find more in Robert's[1] and Artifact Technical Notes'[2] blog. One discussion[3] that can help as well.

Regards

[1] http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/

[2] http://blog.artifact-software.com/tech/?p=121

[3] http://maven.40175.n5.nabble.com/Aggregate-POM-for-thirdparty-package-dependencies-not-downloaded-td113927.html

Gilberto
  • 893
  • 1
  • 13
  • 28