Search code examples
mavenappletuberjar

maven - How to build uberjars with dependencies


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 -

  1. Maven Assembly plugin - This can build custom jars from the classes generated by the maven module. Third party dependencies cant be included.
  2. Use ant through Maven - Use maven-dependency-plugin to unpack dependencies and then pack the applet jars through ant scripts.
  3. 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.


Solution

  • You can include dependencies using the assembly plugin with the dependencySet elements, see:

    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>