WAR
note
This help topic is in development and will be updated in the future.
A WAR archive allows you to easily deploy your application inside your web container / servlet container, by just copying it to its webapps folder. Ktor supports two popular servlet containers: Jetty and Tomcat. It also serves when deploying to google app engine.
To generate a war file, you can use the gretty gradle plugin. You also need a WEB-INF/web.xml which looks like this:

Xml
Groovy

1. <?xml version="1.0" encoding="ISO-8859-1" ?>
3. <web-app xmlns="http://java.sun.com/xml/ns/javaee"
4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
6. version="3.0">
7. <!-- path to application.conf file, required -->
8. <!-- note that this file is always loaded as an absolute path from the classpath -->
9. <context-param>
10. <param-name>io.ktor.ktor.config</param-name>
11. <param-value>application.conf</param-value>
12. </context-param>
14. <servlet>
15. <display-name>KtorServlet</display-name>
16. <servlet-name>KtorServlet</servlet-name>
17. <servlet-class>io.ktor.server.servlet.ServletApplicationEngine</servlet-class>
19. <!-- required! -->
20. <async-supported>true</async-supported>
22. <!-- 100mb max file upload, optional -->
23. <multipart-config>
24. <max-file-size>304857600</max-file-size>
25. <max-request-size>304857600</max-request-size>
26. <file-size-threshold>0</file-size-threshold>
27. </multipart-config>
28. </servlet>
30. <servlet-mapping>
31. <servlet-name>KtorServlet</servlet-name>
32. <url-pattern>/</url-pattern>
33. </servlet-mapping>
35. </web-app>
This gradle buildscript defines several tasks that you can use to run your application.
note
In the case where you only need to generate a war file, there is a
wartask defined in the war plugin. Just run./gradlew warand it will generate a/build/libs/projectname.warfile. For a full example: <https://github.com/ktorio/ktor-samples/tree/1.3.0/deployment/jetty-war>
