2

I am attempting to run Xstream in a netbeans proof of concept project. 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. Any other possible thing that would cause java not to recognize the Xstream class at runtime even though it is fine at compile time?

Thanks

Jimmy

Jimmy
  • 175
  • 1
  • 3
  • 17
  • 1
    Try adding xml-pull-x.x.jar (required version). Looks like xStream depends on it. http://www.findjar.com/class/org/xmlpull/v1/XmlPullParserException.html – Lokesh Gupta Nov 19 '12 at 05:18

2 Answers2

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

It seems you are missing required jars in classpath.

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)

kosa
  • 65,990
  • 13
  • 130
  • 167
  • This may well be the case. I had the jar in my compile time library, but it was not in the run time library. I just added it to the run time and still get the same answer. I am more of a C# guy and so maybe I am missing something else. Is there anything else required to add the jar to my class path? Thanks for the help. – Jimmy – Jimmy Nov 19 '12 at 05:12
  • Is this web application (or) standalone? How you have added jars to runtime? I don't see any other possibility for this issue. – kosa Nov 19 '12 at 05:15
  • It is a standalone netbeans java application. I added the stream-1.4.3.jar to both the compile and run time libraries using the tools antlibraries menu and selecting addjar in each tab. There may well be something I am still missing because I have spent the past 5+ years in Visual Studio and just a few months in netbeans. – Jimmy Nov 19 '12 at 05:19
  • I don't think just stream.jar is enough. You need to add all other dependent jars also. – kosa Nov 19 '12 at 05:20
  • Yes it was that I had to find the xmlpull jar deeper in the xstream folders and pull that in to separately. Thanks for the help. – Jimmy Nov 19 '12 at 05:46
0

Use different constructor i.e.

new Xstream(new StaxDriver())

see XStream XmlPullParserException

Community
  • 1
  • 1
Kalpesh Soni
  • 6,879
  • 2
  • 56
  • 59