jetty-test

来源:互联网 发布:windows禁用数字签名 编辑:程序博客网 时间:2024/06/17 11:28

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();    }}
原创粉丝点击