Fat JAR

A fat-jar (or uber-jar) archive is a normal jar file single archive packing all the dependencies togetherso it can be run a standalone application directly using Java:

java -jar yourapplication.jar

This is the preferred way for running it in a container like docker, when deploying to herokuor when being reverse-proxied with nginx.

Gradle

When using Gradle, you can use the shadow gradle plugin to generate it. For example,to generate a fat JAR using netty as an engine:

build.gradle

1. buildscript {
2. repositories {
3. jcenter()
4. }
5. dependencies {
6. classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
7. }
8. }

10. apply plugin: 'com.github.johnrengelman.shadow'
11. apply plugin: 'kotlin'
12. apply plugin: 'application'

14. //mainClassName = 'io.ktor.server.netty.DevelopmentEngine' // For versions < 1.0.0-beta-3
15. mainClassName = 'io.ktor.server.netty.EngineMain' // Starting with 1.0.0-beta-3

17. // This task will generate your fat JAR and put it in the ./build/libs/ directory
18. shadowJar {
19. manifest {
20. attributes 'Main-Class': mainClassName
21. }
22. }

build.gradle.kts

1. plugins {
2. application
3. kotlin("jvm") version "1.3.21"
4. // Shadow 5.0.0 requires Gradle 5+. Check the shadow plugin manual if you're using an older version of Gradle.
5. id("com.github.johnrengelman.shadow") version "5.0.0"
6. }

8. application {
9. mainClassName = "io.ktor.server.netty.EngineMain"
10. }

12. tasks.withType<Jar> {
13. manifest {
14. attributes(
15. mapOf(
16. "Main-Class" to application.mainClassName
17. )
18. )
19. }
20. }

Maven

When using Maven, you can generate a fat JAR archive with the maven-assembly-plugin. For example, to generatea fat JAR using netty as an engine:

pom.xml

1. <plugin>
2. <groupId>org.apache.maven.plugins</groupId>
3. <artifactId>maven-assembly-plugin</artifactId>
4. <version>3.1.0</version>
5. <configuration>
6. <descriptorRefs>
7. <descriptorRef>jar-with-dependencies</descriptorRef>
8. </descriptorRefs>
9. <archive>
10. <manifest>
11. <addClasspath>true</addClasspath>
12. <mainClass>io.ktor.server.netty.EngineMain</mainClass>
13. </manifest>
14. </archive>
15. </configuration>
16. <executions>
17. <execution>
18. <id>assemble-all</id>
19. <phase>package</phase>
20. <goals>
21. <goal>single</goal>
22. </goals>
23. </execution>
24. </executions>
25. </plugin>