随笔 - 0, 文章 - 2, 评论 - 0, 引用 - 0
数据加载中……

在java-web项目中嵌入jetty,快速进行调试!

      首先,在pom.xml加入jettyjar包以及支持jspjar包:
       <dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>7.2.2.v20101205</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jsp-2.1-glassfish</artifactId>
<version>2.1.v20100127</version>
</dependency>
       创建一个java类:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class GameAdmin {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Server server = buildNormalServer(8080, "/gameweb");
            server.start();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    /**
     * 创建用于正常运行调试的Jetty Server, 以src/main/webapp为Web应用目录.
     
*/
    public static Server buildNormalServer(int port, String contextPath) {
        Server server = new Server(port);
        WebAppContext webContext = new WebAppContext("src/main/webapp", contextPath);
        webContext.setClassLoader(Thread.currentThread().getContextClassLoader());
        server.setHandler(webContext);
        server.setStopAtShutdown(true);
        return server;
    }

}

posted on 2014-03-04 15:40 乐随心动 阅读(214) 评论(0)  编辑  收藏 所属分类: java-web


只有注册用户登录后才能发表评论。


网站导航: