Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually, I didn't check what the <code>maven-shade-plugin</code> is doing exactly (or any other plugin) as maven 2 has everything built-in to create a megajar or uberjar. You just have to use the maven-assembly-plugin with the predefined <code>jar-with-dependencies</code> descriptor.</p> <p>Just add this snippet to your <code>pom.xml</code> to customize the manifest:</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt; &lt;configuration&gt; &lt;archive&gt; &lt;manifest&gt; &lt;mainClass&gt;my.package.to.my.MainClass&lt;/mainClass&gt; &lt;/manifest&gt; &lt;/archive&gt; &lt;/configuration&gt; &lt;/plugin&gt; </code></pre> <p>And the following command will generate your uberjar:</p> <pre><code>mvn assembly:assembly -DdescriptorId=jar-with-dependencies </code></pre> <p>But, again, the default behavior of this descriptor is to unpack dependencies (like the maven-shade-plugin). To be honest, I don't get why this is a problem but, if this is really not what you want, you can use your own custom assembly descriptor.</p> <p>To do so, first, create your assembly descriptor, let's say <code>src/assembly/uberjar.xml</code>, with the following content:</p> <pre><code>&lt;assembly&gt; &lt;id&gt;uberjar&lt;/id&gt; &lt;formats&gt; &lt;format&gt;jar&lt;/format&gt; &lt;/formats&gt; &lt;includeBaseDirectory&gt;false&lt;/includeBaseDirectory&gt; &lt;dependencySets&gt; &lt;dependencySet&gt; &lt;unpack&gt;false&lt;/unpack&gt; &lt;scope&gt;runtime&lt;/scope&gt; &lt;useProjectArtifact&gt;false&lt;/useProjectArtifact&gt; &lt;/dependencySet&gt; &lt;/dependencySets&gt; &lt;fileSets&gt; &lt;fileSet&gt; &lt;directory&gt;${project.build.outputDirectory}&lt;/directory&gt; &lt;outputDirectory&gt;/&lt;/outputDirectory&gt; &lt;/fileSet&gt; &lt;/fileSets&gt; &lt;/assembly&gt; </code></pre> <p>Then, configure the maven-assembly-plugin to use this descriptor and to add the dependencies to the <code>Class-Path</code> entry of the manifest:</p> <pre><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt; &lt;configuration&gt; &lt;descriptors&gt; &lt;descriptor&gt;src/assembly/uberjar.xml&lt;/descriptor&gt; &lt;/descriptors&gt; &lt;archive&gt; &lt;manifest&gt; &lt;mainClass&gt;my.package.to.my.MainClass&lt;/mainClass&gt; &lt;addClasspath&gt;true&lt;/addClasspath&gt; &lt;/manifest&gt; &lt;/archive&gt; &lt;/configuration&gt; &lt;!-- &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;single&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; --&gt; &lt;/plugin&gt; </code></pre> <p>Finally run <code>mvn assembly:assembly</code> to produce your uberjar. </p> <p>Optionally, uncomment the <code>executions</code> element to bind the assembly plugin on the <code>package</code> phase (and have the assembly produced as part of the normal build).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload