在pom.xml中增加以下配置,引入jetty相关jar包,其中${jetty.version}是具体的jetty的版本,我用的是6.1.25,用其它版本应该也是可以的:
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-jetty</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
注释掉以下配置,因为会和引入的jetty冲突:
<!--
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
-->
然后重新运行:mvn eclipse:eclipse
在eclipse中右键刷新工程,在src\main\java\test下增加下面这个类
package test;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;
public class StartJetty {
public static final int PORT = 8080;
public static final String CONTEXT = "/jeecg";
public static final String BASE_URL = "http://localhost:8080/jeecg";
public static void main(String[] args) throws Exception {
Server server = buildNormalServer(PORT, CONTEXT);
server.start();
System.out.println("Hit Enter in console to stop server");
if (System.in.read() != 0) {
server.stop();
System.out.println("Server stopped");
System.exit(0);
}
}
public static Server buildNormalServer(int port, String contextPath) {
Server server = new Server(port);
WebAppContext webContext = new WebAppContext("src/main/webapp", contextPath);
webContext.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setHandler(webContext);
server.setStopAtShutdown(true);
return server;
}
}
然后每次只要运行这个类就可以愉快的进行调试运行啦!
这个类是参考spring-side工程的,谢谢江南白衣!