Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer异常
今天做了一个java对象转Map的例子,执行的时候报错了,如下:
Exceptioninthread"main"java.lang.NoClassDefFoundError:org/apache/commons/collections/Transformer
atjava.lang.ClassLoader.defineClass1(NativeMethod)
atjava.lang.ClassLoader.defineClass(ClassLoader.java:621)
atjava.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
atjava.net.URLClassLoader.defineClass(URLClassLoader.java:260)
atjava.net.URLClassLoader.access$000(URLClassLoader.java:56)
atjava.net.URLClassLoader$1.run(URLClassLoader.java:195)
atjava.security.AccessController.doPrivileged(NativeMethod)
atjava.net.URLClassLoader.findClass(URLClassLoader.java:188)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:307)
atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:252)
atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
atorg.apache.commons.beanutils.BeanMap.createTypeTransformers(BeanMap.java:132)
atorg.apache.commons.beanutils.BeanMap.(BeanMap.java:68)
atcom.example2.pojo.PojoToMap.objectToMap(PojoToMap.java:23)
atcom.example2.pojo.PojoToMap.main(PojoToMap.java:16)
Causedby:java.lang.ClassNotFoundException:org.apache.commons.collections.Transformer
atjava.net.URLClassLoader$1.run(URLClassLoader.java:200)
atjava.security.AccessController.doPrivileged(NativeMethod)
atjava.net.URLClassLoader.findClass(URLClassLoader.java:188)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:307)
atsun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
atjava.lang.ClassLoader.loadClass(ClassLoader.java:252)
atjava.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
...16more
先贴上本例的主要代码吧:
packagecom.example2.pojo; importjava.util.Map; importjava.util.Set; importorg.apache.commons.beanutils.BeanMap; publicclassPojoToMap{ /** *@paramargs */ publicstaticvoidmain(String[]args){ Employeeemployee=newEmployee(); employee.setName("张三"); employee.setAge(30); Mapmap; try{ map=objectToMap(employee); Set>set=map.entrySet(); for(Map.Entry entry:set){ System.out.println(entry.getKey()+":"+entry.getValue()); } }catch(Exceptione){ e.printStackTrace(); } } publicstaticMap,?>objectToMap(Objectobj){ if(obj==null) returnnull; returnnewBeanMap(obj); } }
Employee类:
packagecom.example2.pojo; publicclassEmployee{ privateStringname; privateIntegerage; publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } publicIntegergetAge(){ returnage; } publicvoidsetAge(Integerage){ this.age=age; } }
从报错信息上看,是缺少了org.apache.commons.collections.Transformer类,网上下载了commons-collections-3.2.1.jar包,引入后,重新执行,成功。
到此这篇关于Causedby:java.lang.ClassNotFoundException:org.objectweb.asm.Type异常的文章就介绍到这了,更多相关org.objectweb.asm.Type异常内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!