javaWeb自定义Jetty服务启动项目

pom.xml 添加jetty

    <dependency>
            <groupId>org.eclipse.jetty.aggregate</groupId>
            <artifactId>jetty-all</artifactId>
            <version>9.2.14.v20151106</version>
      </dependency>
      <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
      </dependency>
      <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-jsp</artifactId>
             <version>9.2.15.v20160210</version>
      </dependency>

项目中启动JettyServer main方法运行

package com.qxw;

import java.util.HashMap;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;

import com.sun.javafx.collections.MappingChange.Map;

public class JettyServer {

     public static void main(String[] args) {

            //指定端口号
            int port = 8080;
            Server server = new Server(port);
            WebAppContext webAppContext = new WebAppContext("webapp","/web");  

            webAppContext.setDescriptor("webapp/WEB-INF/web.xml");  
            webAppContext.setResourceBase("src/main/webapp");  
            webAppContext.setDisplayName("qxw-spring");   //项目名
            webAppContext.setClassLoader(Thread.currentThread().getContextClassLoader());  
            webAppContext.setConfigurationDiscovered(true);  
            webAppContext.setParentLoaderPriority(true);  


            server.setHandler(webAppContext);  
            System.out.println(webAppContext.getContextPath());  
            System.out.println(webAppContext.getDescriptor());  
            System.out.println(webAppContext.getResourceBase());  
            System.out.println(webAppContext.getBaseResource()); 

            try {  
                 server.start();
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
            System.out.println("server is  start, port is "+port+"............");  
        }

}

猜你喜欢

转载自blog.csdn.net/u010391342/article/details/80855546