http://www.javadby.com/shiyongjiqiao/20071205/3737.html
java.lang.ClassNotFoundException
分析:
Digester类的getClassLoader方法
/**
* Return the class loader to be used for instantiating application objects
* when required. This is determined based upon the following rules:
* <ul>
* <li>The class loader set by <code>setClassLoader()</code>, if any</li>
* <li>The thread context class loader, if it exists and the
* <code>useContextClassLoader</code> property is set to true</li>
* <li>The class loader used to load the Digester class itself.
* </ul>
*/
public ClassLoader getClassLoader() {
if (this.classLoader != null) {
return (this.classLoader);
}
if (this.useContextClassLoader) {
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
return (classLoader);
}
}
return (this.getClass().getClassLoader());
}
默认使用当前线程上下文的ClassLoader或当前类的ClassLoader
解决方法:
1) 通过配置属性
Digester用来解析应用系统的配置文件,其本身也有很可配置的属性。
|
2)通过 setClassLoader
/**
* Set the class loader to be used for instantiating application objects
* when required.
*
* @param classLoader The new class loader to use, or <code>null</code>
* to revert to the standard rules
*/
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
如:digester.setClassLoader(this.getClass().getClassLoader());