Caused by: java.lang.ClassNotFoundException: org.apache.commons.collections.Transformer异常
今天做了一个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异常内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
IntelliJ IDEA社区版2021.3配置SpringBoot项目详细教程及失败案例
IntelliJ IDEA 2021.3.3是一款集成开发环境,用于Java和其他编程语言的开发,下面这篇文章主要给大家介绍了关于IntelliJ IDEA社区版2021.3配置SpringBoot项目详细教程及失败案例的相关资料,需要的朋友可以参考下2024-03-03
最新评论