maven
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.8.v20121106</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>8.1.19.v20160209</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.8.v20121106</version>
<scope>test</scope>
</dependency>
Main
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class Server_Test {
public static void main(String[] args) throws Exception {
//创建一个server
Server server = new Server(8999);
serverStart(server);
}
protected static void serverStart(Server server) throws Exception {
WebAppContext context = new WebAppContext();
String webapp = "xxx\\src\\main\\webapp\\";
System.out.println("webapp:" + webapp);
context.setDescriptor(webapp + "\\WEB-INF\\web.xml"); //指定web.xml配置文件
context.setResourceBase(webapp); //指定webapp目录
context.setContextPath("/monitor");
context.setParentLoaderPriority(true);
server.setHandler(context);
server.start();
}
}
420

被折叠的 条评论
为什么被折叠?



