Maven: Creating multiple jars for dependencies
I successively converted a Java project which was built with Ant into a Maven project. Dependency resolution, compilation and packaging works just fine. I have a problem though:
I've only managed to create one single fat jar with the application and all d开发者_Go百科ependencies. Project specification requires that I have
- A jar file containing the application
- A jar file containing dependencies from vendor A
- A jar file containing all other dependencies
Here's my question: Can this easily be done with Maven or does it violate the Maven philosophy? I thought of creating a assembly descriptor, although i'm not yet sure how to do it exactly.
Comments and thoughts on this are highly appreciated.
The maven-assembly-plugin can do this if you configure multiple executions of it with multiple assembly descriptors, one for each of your three desired packages. This answer assumes that by 'jars' you mean 'distribution containers'. If by 'jars' you mean 'things that go into classpath', then you need to use the maven-shade-plugin and make a multi-module project.
It's a bad idea to try to build more than one thing that ends up in a classpath in a single maven project, since that involves classifiers, and there are corner cases. To combine multiple things into jars, you use the maven-shade-plugin to pull in the contents of multiple things and spit out a combined jar.
精彩评论