Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer异常

时间:2021-05-20

今天做了一个java对象转Map的例子,执行的时候报错了,如下:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/Transformer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at org.apache.commons.beanutils.BeanMap.createTypeTransformers(BeanMap.java:132)
at org.apache.commons.beanutils.BeanMap.<clinit>(BeanMap.java:68)
at com.example2.pojo.PojoToMap.objectToMap(PojoToMap.java:23)
at com.example2.pojo.PojoToMap.main(PojoToMap.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 16 more

先贴上本例的主要代码吧:

package com.example2.pojo; import java.util.Map;import java.util.Set; import org.apache.commons.beanutils.BeanMap; public class PojoToMap { /** * @param args */ public static void main(String[] args) { Employee employee = new Employee(); employee.setName("张三"); employee.setAge(30); Map map; try { map = objectToMap(employee); Set<Map.Entry<String, Object>> set = map.entrySet(); for (Map.Entry<String, Object> entry : set) { System.out.println(entry.getKey() + " : " + entry.getValue()); } } catch (Exception e) { e.printStackTrace(); } } public static Map<?, ?> objectToMap(Object obj) { if (obj == null) return null; return new BeanMap(obj); }}

Employee类:

package com.example2.pojo; public class Employee { private String name; private Integer age; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; }}

从报错信息上看,是缺少了org.apache.commons.collections.Transformer类,网上下载了commons-collections-3.2.1.jar包,引入后,重新执行,成功。

到此这篇关于Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常的文章就介绍到这了,更多相关org.objectweb.asm.Type异常内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章