Ktor 2.3.12 Help

Creating fat JARs using the Maven Assembly plugin

The Maven Assembly plugin provides the ability to combine project output into a single distributable archive that contains dependencies, modules, site documentation, and other files.

Configure the Assembly plugin

To build an assembly, you need to configure the Assembly plugin first:

  1. Navigate to the pom.xml file and ensure the main application class is specified:

    <properties> <main.class>com.example.ApplicationKt</main.class> </properties>
  2. Add the maven-assembly-plugin to the plugins block as follows:

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.6</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>${main.class}</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>

Build an assembly

To build an assembly for the application, open the terminal and execute the following command:

mvn package

This will create a new target directory for the assembly, including the .jar files.

Run the application

To run the built application, follow the steps below:

  1. In a new terminal window, use the java -jar command to run the application. For the sample project it looks like the following:

    java -jar target/tutorial-server-get-started-maven-0.0.1-jar-with-dependencies.jar
  2. You will see a confirmation message once your app is running:

    [main] INFO Application - Responding at http://0.0.0.0:8080
  3. Click on the URL link to open the application in your default browser:

    Output of generated ktor project
Last modified: 02 April 2024