接前一篇文章,json-lib将xml转json报错java.lang.NoClassDefFoundError: nu/xom/ParentNode,具体错误如下:
Exception in thread "main" java.lang.NoClassDefFoundError: nu/xom/ParentNode
at com.handscape.Demo1.main(Demo1.java:33)
Caused by: java.lang.ClassNotFoundException: nu.xom.ParentNode
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)
... 1 more
后来终于在网上找到原因是因为缺少jar所致,引入xom的jar,
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>
完整json-lib的maven dependency如下所示:
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>