posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

tomcat 调试 扩展

Posted on 2008-08-01 18:46 G_G 阅读(1228) 评论(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 ;
    }
    

}


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


网站导航: