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:
Go to the
pom.xml
file and make sure the main application class is specified:<properties> <main.class>com.example.ApplicationKt</main.class> </properties>If you use EngineMain without the explicit
main
function, the application's main class depends on the used engine and might look as follows:io.ktor.server.netty.EngineMain
.Add
maven-assembly-plugin
to theplugins
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:
When this build completes, you should see the ktor-maven-sample-0.0.1-jar-with-dependencies.jar
file in the target
directory.
Run the application
To run the built application:
Open the terminal and execute the following command to run the application:
java -jar target/ktor-maven-sample-0.0.1-jar-with-dependencies.jarWait until the following message is shown:
[main] INFO Application - Responding at http://0.0.0.0:8080You can click the link to open the application in a default browser: