1.新建一个maven工程。
一直下一步即可,最后finish.
2.pom.xml配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.superv</groupId>
<artifactId>jfinal</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>jfinal Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jfinal/jfinal -->
<dependency>
<groupId>com.jfinal</groupId>
<artifactId>jfinal</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<!-- jetty配置 -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<configuration>
<connectors>
<connector implementation="org.eclipse.jetty.server.bio.SocketConnector">
<port>8082</port>
</connector>
</connectors>
<stopKey />
<stopPort />
</configuration>
</plugin>
</plugins>
</build>
</project>
3.web.xml配置
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" ><web-app> <display-name>Archetype Created Web Application</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>cn.superv.SysConfig</param-value> </init-param> </filter> <filter-mapping> <filter-name>jfinal</filter-name> <url-pattern>/*</url-pattern> </filter-mapping></web-app>
4.系统加载时的类SysConfig类。
package cn.superv;打印结果:
import com.jfinal.config.*;
import com.jfinal.template.Engine;
/**
* Created by Administrator on 2017/8/10 0010.
*/
public class SysConfig extends JFinalConfig{
@Override
public void configConstant(Constants constants) {
System.out.println("configConstant"+1);
}
@Override
public void configRoute(Routes routes) {
System.out.println("configRoute"+2);
}
@Override
public void configEngine(Engine engine) {
System.out.println("configEngine"+3);
}
@Override
public void configPlugin(Plugins plugins) {
System.out.println("configPlugin"+4);
}
@Override
public void configInterceptor(Interceptors interceptors) {
System.out.println("configInterceptor"+5);
}
@Override
public void configHandler(Handlers handlers) {
System.out.println("configHandler"+6);
}
}