隨筆 - 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 樂隨心動 閱讀(212) 評論(0)  編輯  收藏 所屬分類: java-web


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 文成县| 青铜峡市| 台前县| 军事| 元谋县| 永泰县| 通山县| 永平县| 九江市| 唐河县| 海南省| 沙坪坝区| 刚察县| 马关县| 蕉岭县| 厦门市| 佛教| 陇西县| 陈巴尔虎旗| 腾冲县| 遂平县| 涡阳县| 新和县| 台山市| 宽城| 茌平县| 晋中市| 儋州市| 高陵县| 建宁县| 桐柏县| 林周县| 瓦房店市| 子长县| 白沙| 鹤峰县| 木里| 石嘴山市| 且末县| 平凉市| 乌鲁木齐市|