# 1.8 Development without Maven

The demonstration below uses Eclipse Java EE edition as an example. You can download it from: https://www.eclipse.org/downloads/packages/

# 1. Create a Dynamic Web Project

1.png

# 2. Fill in the basic project information

2.png

Note in the above image: Always select "None" for the Target runtime.

3.png Important: The Default out folder here must be consistent with the WebRoot\WEB-INF\classes directory to use JFinal's integrated Jetty for project startup.

4.png

Note in the above image: You can also use the default value WebContent, but in the previous step, WebRoot\WEB-INF\classes should be changed to WebContent\WEB-INF\classes to match.

# 5. Add JFinal library files

Copy jfinal-5.0.0.jar and jetty-server-2019.3.jar to the project's WEB-INF\lib directory. Note: The jetty-server-2019.3.jar is used during development and isn't needed in a production environment.

The required jar files can be downloaded from the jfinal.com homepage. The file jfinal-5.0.0-all.zip contains commonly used jar files and instructions on how to use them.

# 6. Modify web.xml

Add the following content to web.xml:

<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>
1
2
3
4
5
6
7
8
9
10
11
12

# 7. Add Java files

Create a demo package in the project's src directory. Inside the demo package, create the DemoConfig file with the following content:

package demo;
import com.jfinal.config.*;
public class DemoConfig extends JFinalConfig {
    public void configConstant(Constants me) {
       me.setDevMode(true);
    }
    
    public void configRoute(Routes me) {
       // jfinal 4.9.03 版新增了路由扫描功能,不必手动添加路由
       // me.add("/hello", HelloController.class);
       
       // 使用路由扫描,参数 "demo." 表示只扫描 demo 包及其子包下的路由
       me.scan("demo.");
    }
    
    public void configEngine(Engine me) {}
    public void configPlugin(Plugins me) {}
    public void configInterceptor(Interceptors me) {}
    public void configHandler(Handlers me) {}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

Note: The DemoConfig.java file's package and its filename must match the param-value tag in web.xml (in this example, it's demo.DemoConfig).

Create the HelloController class file in the demo package with the following content:

package demo;
import com.jfinal.core.Controller;
 
@Path("/hello")
public class HelloController extends Controller {
    public void index() {
       renderText("Hello JFinal World.");
    }
}
1
2
3
4
5
6
7
8
9

# 8. Start the project

Create a start-up item as shown: 5.png

Right-click on Java Application and select the New menu item to create a new Java Application start-up item as shown: 6.png

In the Main class input box on the right window, input: com.jfinal.core.JFinal and click the Debug button to start the project: 7.png

Alternatively, you can use any main method to start the integrated jetty as shown:

public static void main(String[] args) {
	JFinal.start("WebRoot", 80, "/", 5);
}
1
2
3

# 9. Open a browser to see the result

Open a browser and enter: http://localhost/hello. If you see "Hello JFinal World," it means the project framework setup is complete. For a complete demo example, download from the JFinal official website: http://www.jfinal.com

Note: When developing or running a project under tomcat, you should first delete the jetty-server-xxx.jar package to avoid conflicts. Tomcat starts the project differently from the above method because the above method requires the jetty-server-xxx.jar.

We strongly recommend using the standard Maven project structure for development. This section describes the older method of manually adding jar files.

Last Updated: 9/22/2023, 9:39:45 AM