Creating the application distribution
The Ktor Gradle plugin automatically applies the Gradle Application plugin, which provides the ability to package applications, including code dependencies and generated start scripts.
In this topic, you will learn how to package and run a Ktor application.
Configure the Ktor plugin
To create the application distribution, you need to apply the Ktor plugin first:
Open the build.gradle.kts file and add the plugin to the
plugins {}block:plugins { alias(ktorLibs.plugins.ktor) }Ensure that the main application class is configured:
application { mainClass.set("com.example.ApplicationKt") }
Package the application
The Application plugin provides various ways for packaging your application. For example, the installDist task installs the application with all runtime dependencies and start scripts. To create full distribution archives, you can use the distZip and distTar tasks.
To install your application with all runtime dependencies and start scripts, open a new terminal window and run the installDist task:
The Application plugin creates an image of the application in the build/install/<project_name> folder.
Run the application
To run the packaged application, follow the steps below:
In the terminal, navigate to the build/install/<project_name>/bin folder.
Depending on your operating system, run the
<project_name>or<project_name>.batexecutable, for example:./ktor-samplektor-sample.batWait until the following message is shown:
[main] INFO Application - Responding at http://0.0.0.0:8080Open the link in a browser to see a running application:
