简体   繁体   English

XStream noclassdeffound 错误

[英]XStream noclassdeffound error

I am attempting to run Xstream in a netbeans proof of concept project.我正在尝试在 netbeans 概念验证项目中运行 Xstream。 I have the following code.我有以下代码。

XStream xstream = new XStream();
FileOutputStream fis = new FileOutputStream("Test.xml");
xstream.toXML(company, fis);

The program is crashing on the first line of code with the following error.程序在第一行代码崩溃并出现以下错误。

Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
    at com.thoughtworks.xstream.XStream.<init>(XStream.java:336)
    at Parser.XParser.Parse(XParser.java:24)
    at rejaxbtest.REJAXBTest.main(REJAXBTest.java:39)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 3 more
Java Result: 1

I have seen one other thread with this problem, but the answer that was given was put the jar in the project lib directory, but netbeans has already correctly finished that task.我已经看到另一个线程有这个问题,但给出的答案是将 jar 放在项目 lib 目录中,但 netbeans 已经正确完成了该任务。 Any other possible thing that would cause java not to recognize the Xstream class at runtime even though it is fine at compile time?任何其他可能导致 java 在运行时无法识别 Xstream 类的事情,即使它在编译时很好?

Thanks谢谢

Jimmy吉米

Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException

It seems you are missing required jars in classpath.您似乎在类路径中缺少必需的 jar。

Make sure all jars required (the jars you have at compile time) are in runtime classpath (if it is web application, copy those jars to lib folder)确保所有需要的 jars(你在编译时拥有的 jars)都在运行时类路径中(如果它是 web 应用程序,将这些 jars 复制到 lib 文件夹)

Use different constructor ie使用不同的构造函数即

new Xstream(new StaxDriver())

see XStream XmlPullParserExceptionXStream XmlPullParserException

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM