Olivier J.
Olivier J.

Reputation: 3165

Maven : include JAR's classes into another JAR

I want to generate JAR file with some classes of another JAR (but not all classes). I know I can use maven-dependency-plugin:copy-dependencies to include JAR into another JAR but how can I include only some classes and not the entire JAR please ?

Upvotes: 2

Views: 3315

Answers (2)

Stephen Connolly
Stephen Connolly

Reputation: 14096

Another solution is the Maven Shade Plugin which allows including dependencies, but also allows transforming their package names (along will all references to them) so that the resulting überjar is safe from classpath duplicates if the bundled JAR is also on the classpath.

One example is this pom.xml where for example the XStream classes used are relocated to a different package. This allows the jar file to be used in an application that uses a different and incompatible version of XStream (in this case the artifact is used in a Jenkins plugin)

Upvotes: 0

Nazar Annagurban
Nazar Annagurban

Reputation: 336

You can include/exclude in the configuration of the maven-dependency-plugin.

See Unpacking specific artifacts

Upvotes: 2

Related Questions