jeecg3.5使用内嵌的jetty进行调试开发

在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

相关文章
相关标签/搜索