Fat Jar
We need to build our Javalin project in a way that all the code is collected in on big fat jar file in the /target folder. Maven can do that.
Make sure you have this in pom.xml under <project>:
<properties>
<maven.compiler.release>21</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Add this to your pom.xml(as the last section in the file before the closing </project>):
<build>
<finalName>app</finalName>
<plugins>
<!-- Create an executable fat JAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>app.Main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Vigtigt: app.Main skal være den klasse, der indeholder applikationens main()-metode. Hvis din klasse har et andet package eller navn, skal du ændre værdien.
Build the fat jar with Maven Package.
You can execute Maven Package in IntelliJ by opening the Maven tab, Lifecycle, and double clicking on package.
Alternatively, you can use the terminal if Maven is installed:
mvn clean package
The generated fat JAR file can be found in target/app.jar.
Now you have a app.jar fil in the project’s target folder. You can execute Maven Package in IntelliJ by opening the Maven tab, Lifecycle, and double clicking on package.