It's interesting because I asked myself the question yesterday, "why do I need an über jar?" And, as it turns out, I don't and probably shouldn't be using an über jar. Alexey correctly answered the question to solve the immediate problem, but I also wanted to post an alternate solution that I figured out for doing things a little bit differently.
Rather than using the shade plugin to build an über jar, I decided to create a standard jar and export all the dependencies needed to run my application. This means that I now use the Maven Jar Plugin to create my jar and the Maven Dependency Plugin to export the libraries. Here's what the build section of the pom.xml
looks like:
<build>
<plugins>
<!-- For copying the libraries to the output directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create the executable jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.test.myserver.App</mainClass>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Since my output directory is target/
, my jar is generated as target/myserver-1.0-SNAPSHOT.jar
and all the dependencies are in target/lib/
. The maven-jar-plugin also build the classpath and points them correctly to the lib/
directory, so I'm pretty much set. This also makes it easier in the future to replace individual libraries as they are updated, rather than uploading an entirely new jar.
Building the jar and copying the dependencies is simply mvn install
from the command line.