Ktor 1.6.7 Help

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. In this topic, we'll show you how to build an assembly and run it for a Ktor application created in the Adding Ktor to an existing Maven project topic.

Prerequisites

Before starting this tutorial, clone the ktor-maven-sample repository.

Configure the Assembly plugin

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

  1. Open the ktor-maven-sample project.

  2. Go to the pom.xml file and add maven-assembly-plugin to the plugins block as follows:

    <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.example.ApplicationKt</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>

    Among other settings, this configuration contains the Main-Class attribute of the JAR manifest for building an executable JAR.

Build an assembly

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

mvn package

When this build completes, you should see the mainModule-1.0-SNAPSHOT-jar-with-dependencies.jar file in the target directory.

Run the application

To run the built application:

  1. Go to the target folder in a terminal.

  2. Execute the following command to run the application:

    java -jar mainModule-1.0-SNAPSHOT-jar-with-dependencies.jar
  3. Wait until the following message is shown:

    [main] INFO Application - Responding at http://0.0.0.0:8080 You can click the link to open the application in a default browser:

    Ktor app in a browser
Last modified: 05 August 2021