问题
I have a maven module generating a jar file. I have been asked to develop a couple of other uberjar files as a byproduct of build process. I have also been told these 2 jar files are applet jar files that will be need include some classes from the dependencies of the maven module.
I looked around and narrowed down to these 3 options -
- Maven Assembly plugin - This can build custom jars from the classes generated by the maven module. Third party dependencies cant be included.
- Use ant through Maven - Use maven-dependency-plugin to unpack dependencies and then pack the applet jars through ant scripts.
- Use Maven shade plugin - Although this plugin is not directly suited for my requirement, I can get it working.
While I can get things working with (b) and (c), I am unable to decide which one to use. One key thing I have noticed is using the dependency plugin is time consuming.
I wanted to know if there are other ways people achieve the same requirement.
回答1:
You can include dependencies using the assembly plugin with the dependencySet
elements, see:
- http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet
Specifically here's an example taken from Andrew E Bruno's blog:
<dependencySets>
<dependencySet>
<outputDirectory></outputDirectory>
<outputFileNameMapping></outputFileNameMapping>
<unpack>true</unpack>
<scope>runtime</scope>
<includes>
<include>commons-lang:commons-lang</include>
<include>commons-cli:commons-cli</include>
</includes>
</dependencySet>
</dependencySets>
回答2:
I finally used the assembly plugin using the same approach you described above. I moved away from shade plugin since I generate several assemblies with resources from outside of maven also and shade plugin does not have great support for such tasks.
来源:https://stackoverflow.com/questions/10096723/maven-how-to-build-uberjars-with-dependencies