Maven 使用Jetty的两种方式

第一种,直接在maven pom文件中引用

   
     
        org.eclipse.jetty.aggregate
        jetty-all-server
        7.0.2.v20100331
     
    
        org.mortbay.jetty
        jsp-2.1-jetty
        7.0.0.pre5
    
    
        javax.servlet
        servlet-api
        2.5
    
    
        javax.servlet.jsp
        jsp-api
        2.0
        
    

 

 public class StartJetty {
	public static void main(String[] args) throws Exception {
		Server server = new Server();

		Connector connector = new SelectChannelConnector();
		connector.setPort(8080);

		server.setConnectors(new Connector[] { connector });

		WebAppContext webAppContext = new WebAppContext("webapp", "/webs");

		// webAppContext.setContextPath("/");
		String path = "src/main/";
		webAppContext.setDescriptor(path+"webapp/WEB-INF/web.xml");
		webAppContext.setResourceBase(path+"webapp");
		webAppContext.setDisplayName("webs");
		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");
	}
}

  第二种方式  

 

直接安装  run-jetty-run 

 

你可能感兴趣的:(Maven)