在pom.xml中增長如下配置,引入jetty相關jar包,其中${jetty.version}是具體的jetty的版本,我用的是6.1.25,用其它版本應該也是能夠的:java
<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衝突:web
<!-- <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:eclipsespring
在eclipse中右鍵刷新工程,在src\main\java\test下增長下面這個類api
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; } }
而後每次只要運行這個類就能夠愉快的進行調試運行啦!app
這個類是參考spring-side工程的,謝謝江南白衣!eclipse