Vojtěch
Vojtěch

Reputation: 12416

Maven Assembly Plugin: Unpacking overwrites different versions of dependencies

I am using Maven assembly plugin with which I generate single Jar file with all dependencies for my application (unpacked by definition in jarlib.xml given here: https://gist.github.com/knyttl/7cc0730ae0fb6947cbda). This dependency.jar can be then put on class path with my application.jar and run as java -cp application.jar:dependencies.jar my.class.Runner. The problem are however multiple versions of the same artifacts when unpacking jars.

For instance I am using org.apache.xmlrpc:xmlrpc-server:jar:3.1.3 which depends on javax.servlet:servlet-api:jar:2.3. In my application I need to use different, newer version of the javax.servlet, but when unpacking, the new version is skipped and the old one is used instead.

  1. Is there a way to ignore the dependency given by xmlrpc-server?
  2. Is there a way to prioritize the newer version of javax.servlet?
  3. Is there a way to create single jar without unpacking the dependencies and being able to use them with -cp application.jar:dependencies.jar? When I tried to build the jar without unpacking, none of the inner jar classes were found when running the application.

Upvotes: 0

Views: 332

Answers (2)

Vojtěch
Vojtěch

Reputation: 12416

The best solution I found is using <exclusions> directly in the <dependency> tag directly in the pom, without any plugins.

Upvotes: 1

John Ament
John Ament

Reputation: 11723

Sounds like what you really want is the shade plugin - the ability to create a single jar with all of these included. https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html

Upvotes: 1

Related Questions