Using IntelliJ I just created a new Maven project and added the following to the pom file http://undertow.io/downloads.html and the following to a Main.java file http://undertow.io/index.html
Now if I run the code all works well, but how do I make this as a "fat jar" that will contain all the dependencies in the pom file and that I'll be able to run by just java -jar my.jar
? Like you are able to do with a Spring Boot app.
Other Maven plugins that can be used to create a fat jar are the Maven Assembley Plugin and the One-Jar Plugin.
Maven is one of the most used tools for Java application development. Maven packaging will create a Jar file without dependencies. Maven provides other plugins using which we can generate the jar with all its dependencies which is usually called FatJar, which is used as an executable Jar file.
A Fat JAR is a single JAR file that contains all the compiled Java classes from your project, and all compiled Java classes from all JAR files your project depends on (see Maven Dependencies ). In this Maven Fat JAR Tutorial I will show you how to create a Fat JAR with Maven.
After configuring the shade plugin in your build the command mvn package will create one single jar with all dependencies merged into it. This is now the correct way to do it. The maven-assembly-plugin documentation states: "If your project wants to package your artifact in an uber-jar, the assembly plugin provides only basic support.
Maven Shade Plugin does this well.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>package.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
1) Add the Spring-boot-maven-plugin
to the pom.xml file
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2) Change the packing to jar
<packaging>jar</packaging>
3) mvn package
will create the executable jar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With