Maven 使用Jetty的兩種方式

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

<dependencies>   
     <dependency>
        <groupId>org.eclipse.jetty.aggregate</groupId>
        <artifactId>jetty-all-server</artifactId>
        <version>7.0.2.v20100331</version>
    </dependency> 
    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jsp-2.1-jetty</artifactId>
        <version>7.0.0.pre5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        </dependency>
    </dependencies>

 

 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 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章