This module exists for strict environments where the ONLY option is to deploy into a Servlet Container. If you are free to deploy a new server technology, we strongly recommend to avoid this and go directly with Netty, Jetty or Undertow.
In order to deploy into a Servlet Container, we need to generate a *.war
file. The next steps guide you on how to do it:
-
Write a
war.activator
file inside thesrc/etc
directory. -
Open a console and type:
mvn clean package
-
Find the
*.war
file in thetarget
directory.
- web-sockets are not supported
- some properties has no effect when deploying into a Servlet Container:
- application.path / contextPath
- appplication.port
- max upload file sizes
- any other server specific property: server., jetty., netty., undertow.
To avoid a headache... make sure to use the contextPath
variable while loading static/dynamic
resources (.css, .js, etc..).
For example:
<html>
<head>
<link rel="stylesheet" text="text/css" href="{{contextPath}}/css/styles.css">
<script src="{{contextPath}}/js/app.js"></script>
</head>
</html>
Here the expression: {{ "{{contextPath" }}}}
correspond to the template engine (handlebars here) or ${contextPath}
for Freemarker.
The presence of the src/etc/war.activator
file triggers a Maven profile. Content of the file doesn't matter, just the presence.
The Maven profile build the *.war
file using the maven-assembly-plugin
. The assembly descriptor can be found
here
A default web.xml
file is generated by the assembly plugin. File looks like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>application.class</param-name>
<param-value>${application.class}</param-value>
</context-param>
<listener>
<listener-class>org.jooby.servlet.ServerInitializer</listener-class>
</listener>
<servlet>
<servlet-name>jooby</servlet-name>
<servlet-class>org.jooby.servlet.ServletHandler</servlet-class>
<load-on-startup>0</load-on-startup>
<!-- MultiPart setup -->
<multipart-config>
<file-size-threshold>0</file-size-threshold>
<!-- Default 200k -->
<max-request-size>${war.maxRequestSize}</max-request-size>
</multipart-config>
</servlet>
<servlet-mapping>
<servlet-name>jooby</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Default upload size is set to 204800b
(200kb). If you need to increase the upload size, add
the war.maxRequestSize
property to pom.xml
:
<properties>
<war.maxRequestSize>1048576</war.maxRequestSize> <!-- 1mb -->
</properties>
When the generated file isn't enough, follow these steps:
- create a dir:
src/etc/war/WEB-INF
- save a
web.xml
file inside that dir - run:
mvn clean package