Initial project: ktor-maven-sample
Final project: ktor-maven-sample, the maven-assembly
branch
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 the ktor-maven-sample application.
Before starting this tutorial, clone the ktor-maven-sample repository.
To build an assembly, you need to configure the Assembly plugin first:
-
Open the ktor-maven-sample project.
-
Go to the
pom.xml
file and addmaven-assembly-plugin
to theplugins
block as follows:{src="https://raw.githubusercontent.com/ktorio/ktor-maven-sample/maven-assembly/pom.xml" lines="55-76"}
Among other settings, this configuration contains the
Main-Class
attribute of the JAR manifest for building an executable JAR.If you use EngineMain without the explicit
main
function, yourMain-Class
depends on the used engine and might look as follows:io.ktor.server.netty.EngineMain
.
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.
To learn how to use the resulting package to deploy your application using Docker, see the help topic.
To run the built application:
- Go to the
target
folder in a terminal. - Execute the following command to run the application:
java -jar mainModule-1.0-SNAPSHOT-jar-with-dependencies.jar
- Wait until the following message is shown:
You can click the link to open the application in a default browser:
[main] INFO Application - Responding at http://0.0.0.0:8080