posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          tomcat 調試 擴展

          Posted on 2008-08-01 18:46 G_G 閱讀(1241) 評論(0)  編輯  收藏 所屬分類: JUnitJspTagjavaGeneral
          參考引用:
          主題:使用全功能Tomcat簡化調試
          讓classpath參數走開


          直接用eclipse 調試 :

          tomcat - > service.xml
          <Context debug="5" docBase="E:/tomcat/tomcatwebroot"
          path="/tomcatwebroot" reloadable="true" privileged="true">
          </Context>


          這引入一個java 文件 到你的 工程中
          import?java.io.File;
          import?java.io.FileFilter;
          import?java.lang.reflect.Method;
          import?java.net.URL;
          import?java.net.URLClassLoader;
          import?java.util.ArrayList;
          import?java.util.List;


          public?class?MainClassLoad?{
          ????
          //commons-lang-2.0.jar
          ????static?String?TOMCAT_HOME?=?"D:\\apache\\apache-tomcat-5.5.20\\apache-tomcat-5.5.20";

          ????
          public?static?void?main(String[]?args)?throws?Exception?{
          ????????System.setProperty(
          "catalina.home",?TOMCAT_HOME);
          ????????
          ????????
          final?ClassLoader?classLoader?=?getClassLoader(new?String[]{
          ????????????????TOMCAT_HOME
          +"\\common\\lib",
          ????????????????TOMCAT_HOME
          +"\\server\\lib",
          ????????????????TOMCAT_HOME
          +"\\bin"
          ????????});
          ????????Object?obj?
          =?getObject(classLoader,"org.apache.catalina.startup.Catalina");
          ????????Method?setConfig?
          =?obj.getClass().getMethod("setConfig",?new?Class[]{String.class});
          ????????setConfig.invoke(obj,?TOMCAT_HOME?
          +?"/conf/server.xml");
          ????????
          ????????Method?start?
          =?obj.getClass().getMethod("start",?new?Class[]{});
          ????????start.invoke(obj,?
          null);
          ????}
          ????
          ????
          ????
          ????
          public?static?Object?getObject(ClassLoader?classLoader,String?className)?throws?Exception{
          ????????
          return?classLoader.loadClass(className).newInstance();
          ????}

          ????
          ????
          public?static?ClassLoader?getClassLoader(String[]?libPath)?throws?Exception{
          ????????List
          <URL>?list?=?new?ArrayList<URL>();
          ????????FileFilter?fileFilter?
          =?new?FileFilter()??
          ?????????{??
          ???????????
          public?boolean?accept(File?dir)??
          ???????????{??
          ?????????????String?name?
          =?dir.getName().toLowerCase();??
          ?????????????
          return?name.endsWith("jar")?||?name.endsWith("zip");??
          ???????????}??
          ?????????};
          ?????????
          ????????
          for(String?stmp?:?libPath){
          ????????????
          for(File?ftmp?:?new?File(stmp).listFiles(fileFilter)?){
          ????????????????list.add(?
          new?URL("file",null,ftmp.getPath())?);???
          ????????????}
          ????????}
          ????????URL[]?urls?
          =?new?URL[list.size()];??
          ?????????
          //?fill?the?urls?array?with?URLs?to?library?files?found?in?libRoot??
          ?????????for(int?i?=?0;?i?<?list.size();?i++)?{??
          ???????????urls[i]?
          =?new?URL("file",null,list.get(i).getPath()?);??
          ?????????}
          ????????ClassLoader?classLoader?
          =?new?URLClassLoader(urls,??
          ?????????????????Thread.currentThread().??
          ?????????????????getContextClassLoader());??
          ????????
          return??classLoader?;
          ????}
          ????

          }

          主站蜘蛛池模板: 思南县| 福清市| 曲松县| 资中县| 芒康县| 麻阳| 岑溪市| 翁牛特旗| 嘉祥县| 长汀县| 深圳市| 临西县| 九江县| 永丰县| 句容市| 盘锦市| 桐柏县| 三门峡市| 锡林浩特市| 德昌县| 灵璧县| 清水河县| 深水埗区| 桓仁| 德保县| 乌兰察布市| 大化| 枣阳市| 成武县| 疏勒县| 云安县| 嘉荫县| 荔浦县| 赤城县| 安吉县| 许昌县| 正宁县| 介休市| 义马市| 淮阳县| 遵义县|