java 使用 commons-beanutils 在 org.apache.commons.logging.LogFactory 上抛出 ClassNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4483880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using commons-beanutils throws ClassNotFoundException on org.apache.commons.logging.LogFactory
提问by darkAngel
I have same code
我有相同的代码
import org.apache.commons.beanutils.PropertyUtils;
public class Reflection {
private double []masElement = {3,5,2,5};
public double getValue(int i){
if (masElement.length>i){
return masElement[i];
}
return 0;
}
public void setValue(int i, int value){
if (masElement.length>i){
masElement[i]=value;
}
}
public static void main(String[] args) {
Reflection n = new Reflection();
try {
System.out.println(PropertyUtils.getProperty(n, "masElement[0]"));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
I have problem and i don't understand why?
我有问题,我不明白为什么?
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.commons.beanutils.ConvertUtilsBean.<init>(ConvertUtilsBean.java:157)
at org.apache.commons.beanutils.BeanUtilsBean.<init>(BeanUtilsBean.java:117)
at org.apache.commons.beanutils.BeanUtilsBean.initialValue(BeanUtilsBean.java:68)
at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:153)
at org.apache.commons.beanutils.BeanUtilsBean.getInstance(BeanUtilsBean.java:80)
at org.apache.commons.beanutils.PropertyUtilsBean.getInstance(PropertyUtilsBean.java:114)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:426)
at same.home.reflection.Reflection.main(Reflection.java:39)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 8 more
回答by BalusC
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
引起:java.lang.ClassNotFoundException:org.apache.commons.logging.LogFactory
You need to put Apache Commons LoggingJAR file in the classpath as well. The Apache Commons Beanutils is namely using it as one of its dependencies.
您还需要将Apache Commons LoggingJAR 文件放在类路径中。Apache Commons Beanutils 即使用它作为其依赖项之一。