开发者

Using commons-beanutils throws ClassNotFoundException on org.apache.commons.logging.LogFactory

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$1.initialValue(BeanUtilsBean.java:68)
at org.apache.commons.beanutils.ContextClassLoaderLocal.get(ContextClassLoaderLocal.java:153)
at org.apache.commons.开发者_如何学JAVAbeanutils.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$1.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


Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory

You need to put Apache Commons Logging JAR file in the classpath as well. The Apache Commons Beanutils is namely using it as one of its dependencies.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜