# 1.6 Development under jetty-server
# 1. Create a standard maven project
This is exactly the same as the section related to jfinal undertow.
# 2. Add jetty server and jfinal dependencies
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>5.1.2</version>
</dependency>
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jetty-server</artifactId>
<version>2019.3</version>
<scope>provided</scope>
</dependency>
<!-- The following dependency is only needed when using JSP -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>9.2.26.v20180806</version>
<scope>provided</scope>
</dependency>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
The scope
of the jetty-server dependency is provided
, which is only used during the development phase. It's not required during deployment and will be automatically skipped during packaging.
Note: If you are using IDEA for development, the scope
still needs to be set to compile
to avoid missing jar package warnings. Remember to change it back to provided
during packaging to avoid including unnecessary jar packages.
# 3. Add Java files
This is almost identical to the section related to jfinal undertow, with the only difference being the content within the main method, as shown below:
public static void main(String[] args) {
JFinal.start("src/main/webapp", 80, "/", 5);
}
2
3
# 4. Add JFinalFilter to web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>jfinal offical website</display-name>
<filter>
<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param>
<param-name>configClass</param-name>
<param-value>demo.DemoConfig</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jfinal</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
For development under jetty-server or tomcat, the above XML file needs to be configured.
# 5. Launch the project
This is exactly the same as the section related to jfinal undertow.
# 6. Open the browser to see the results
This is exactly the same as the section related to jfinal undertow.
# 7. Common problem-solving:
- Encountering a NoClassDefFoundError exception
One reason might be that the jar file downloaded to the local maven library is corrupted. Look at which class file threw the NoClassDefFoundError in the exception. Delete its directory in the local maven library and let maven re-download it from the central library. For instance, if you're using jfinal version 3.6, delete the 3.6 subdirectory under the /com/jfinal/jfinal directory in the maven repository.
Another reason could be the inclusion of multiple different versions of the same jar package. Simply delete the redundant ones. The issues mentioned above are fundamentally unrelated to jfinal. They are basic exceptions encountered during Java development.