Skip to content

Commit 68bb92b

Browse files
committed
This module exists for strict environments where you are force 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. Generate a *.war file at build time. The *.war file can be deployed into a Servlet Container. Add the ```jooby-servlet``` dependency to your ```pom.xml```: ```xml <dependency> <groupId>org.jooby</groupId> <artifactId>jooby-ftl</artifactId> <version>{{version}}</version> <scope>provided</scope> </dependency> ``` IMPORTANT: Scope must be ```provided```. Find out the ```maven-assembly-plugin``` section in your ```pom.xml```, it looks like this: ```xml <!-- Build jooby.zip | jooby.war --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jooby.zip</descriptorRef> </descriptorRefs> </configuration> </plugin> ``` Add a new descriptorRef: ```jooby.war``` ```xml <!-- Build jooby.zip | jooby.war --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jooby.zip</descriptorRef> <descriptorRef>jooby.war</descriptorRef> </descriptorRefs> </configuration> </plugin> ``` Run: ```mvn clean package``` and find the ```*.war``` file in the ```target``` directory. * web-sockets are not supported * some properties has no effect when deploying into a Servlet Container: - application.path - appplication.port - any other server specific property: server.*, jetty.*, netty.*, undertow.* The ```maven-assembly-plugin``` generates the *.war file. The assembly descriptor can be found [here](https://github.com/jooby-project/jooby/blob/master/jooby-dist/src/main/resources/assemblies/jooby.war.xml) All it does, is to adapt the project structure to the one required by a Servlet Container. A default web.xml file is generated by the assembly plugin. File looks like: ```xml <?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> ``` It is possible to provide your own ```web.xml``` file too. Follow these steps 1. create a dir: ```src/etc/war/WEB-INF``` 2. save a ```web.xml``` file inside that dir 3. run: ```mvn clean package``` That's all folks! Enjoy it!!!
1 parent 54fd803 commit 68bb92b

4 files changed

Lines changed: 140 additions & 2 deletions

File tree

jooby-servlet/src/main/resources/WEB-INF/web.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
<!-- MultiPart setup -->
1919
<multipart-config>
2020
<file-size-threshold>0</file-size-threshold>
21-
<!-- 200k -->
22-
<max-request-size>204800</max-request-size>
21+
<max-request-size>${war.maxRequestSize}</max-request-size>
2322
</multipart-config>
2423
</servlet>
2524

md/available-modules.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@
1414
### [jdbc](https://github.com/jooby-project/jooby/tree/master/jooby-jdbc)
1515
### [jdbi](https://github.com/jooby-project/jooby/tree/master/jooby-jdbi)
1616
### [hibernate](https://github.com/jooby-project/jooby/tree/master/jooby-hbm)
17+
18+
## servlet deployment
19+
### [servlet](https://github.com/jooby-project/jooby/tree/master/jooby-servlet)

md/doc/jooby-servlet/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# jooby-servlet
2+
3+
This module exists for strict environments where your ONLY option is to deploy into a Servlet Container.
4+
If you are free to deploy a new server technology, we strongly recommend to avoid this and go
5+
directly with netty, jetty or undertow.
6+
7+
## prepare
8+
9+
Generate a *.war file at build time. The *.war file can be deployed into a Servlet Container.
10+
11+
### step 1
12+
13+
Add the ```jooby-servlet``` dependency to your ```pom.xml```:
14+
15+
```xml
16+
<dependency>
17+
<groupId>org.jooby</groupId>
18+
<artifactId>jooby-ftl</artifactId>
19+
<version>{{version}}</version>
20+
<scope>provided</scope>
21+
</dependency>
22+
```
23+
24+
IMPORTANT: Scope must be ```provided```.
25+
26+
### step 2
27+
28+
Find out the ```maven-assembly-plugin``` section in your ```pom.xml```, it looks like this:
29+
30+
```xml
31+
<!-- Build jooby.zip | jooby.war -->
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-assembly-plugin</artifactId>
35+
<configuration>
36+
<descriptorRefs>
37+
<descriptorRef>jooby.zip</descriptorRef>
38+
</descriptorRefs>
39+
</configuration>
40+
</plugin>
41+
```
42+
43+
Add a new descriptorRef: ```jooby.war```
44+
45+
```xml
46+
<!-- Build jooby.zip | jooby.war -->
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-assembly-plugin</artifactId>
50+
<configuration>
51+
<descriptorRefs>
52+
<descriptorRef>jooby.zip</descriptorRef>
53+
<descriptorRef>jooby.war</descriptorRef>
54+
</descriptorRefs>
55+
</configuration>
56+
</plugin>
57+
```
58+
59+
### step 3
60+
61+
Run: ```mvn clean package``` and find the ```*.war``` file in the ```target``` directory.
62+
63+
## limitations
64+
65+
* web-sockets are not supported
66+
* some properties has no effect when deploying into a Servlet Container:
67+
- application.path
68+
- appplication.port
69+
- any other server specific property: server.*, jetty.*, netty.*, undertow.*
70+
71+
## how it works?
72+
73+
The ```maven-assembly-plugin``` generates the *.war file. The assembly descriptor can be found
74+
[here](https://github.com/jooby-project/jooby/blob/master/jooby-dist/src/main/resources/assemblies/jooby.war.xml)
75+
76+
All it does, is to adapt the project structure to the one required by a Servlet Container.
77+
78+
79+
### web.xml
80+
81+
A default web.xml file is generated by the assembly plugin. File looks like:
82+
83+
```xml
84+
<?xml version="1.0" encoding="UTF-8"?>
85+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
86+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
87+
version="3.1">
88+
<context-param>
89+
<param-name>application.class</param-name>
90+
<param-value>${application.class}</param-value>
91+
</context-param>
92+
93+
<listener>
94+
<listener-class>org.jooby.servlet.ServerInitializer</listener-class>
95+
</listener>
96+
97+
<servlet>
98+
<servlet-name>jooby</servlet-name>
99+
<servlet-class>org.jooby.servlet.ServletHandler</servlet-class>
100+
<load-on-startup>0</load-on-startup>
101+
<!-- MultiPart setup -->
102+
<multipart-config>
103+
<file-size-threshold>0</file-size-threshold>
104+
<!-- Default 200k -->
105+
<max-request-size>${war.maxRequestSize}</max-request-size>
106+
</multipart-config>
107+
</servlet>
108+
109+
<servlet-mapping>
110+
<servlet-name>jooby</servlet-name>
111+
<url-pattern>/*</url-pattern>
112+
</servlet-mapping>
113+
</web-app>
114+
```
115+
116+
#### upload size
117+
118+
Default upload size is set to ```204800b``` (200kb). If you need to increase the upload size, add
119+
the ```war.maxRequestSize``` property to ```pom.xml```:
120+
121+
```
122+
<properties>
123+
<war.maxRequestSize>1048576</war.maxRequestSize> <!-- 1mb -->
124+
</properties>
125+
```
126+
127+
#### custom web.xml
128+
129+
It is possible to provide your own ```web.xml``` file too. Follow these steps
130+
131+
1. create a dir: ```src/etc/war/WEB-INF```
132+
2. save a ```web.xml``` file inside that dir
133+
3. run: ```mvn clean package```
134+
135+
That's all folks! Enjoy it!!!

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,7 @@
10221022
<quartz.version>2.2.1</quartz.version>
10231023
<jdbi.version>2.59</jdbi.version>
10241024
<freemarker.version>2.3.22</freemarker.version>
1025+
<war.maxRequestSize>204800</war.maxRequestSize>
10251026

10261027
<!-- Test dependencies -->
10271028
<junit.version>4.11</junit.version>

0 commit comments

Comments
 (0)