Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XStream XmlPullParserException

Tags:

java

xstream

I'm trying to use XStream. I've added the XStream executable Jar file to my project. Executing the following command:

    XStream xstream = new XStream();

Is resulting in the following exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException

at com.thoughtworks.xstream.XStream.<init>(XStream.java:350)
at xstream_test.XmlTrasformer.objectToXml(XmlTrasformer.java:56)
at xstream_test.XmlTrasformer.main(XmlTrasformer.java:31)

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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 3 more

Any idea I might have done wrong? Thanks.

like image 546
user3062233 Avatar asked Feb 09 '14 19:02

user3062233


3 Answers

Make sure you have included all the jars that come with XStream also specially "kxml2.jar" and "xmlpull-1.1.3.1.jar" file. Jar version may deffer incase of yours.

like image 183
A Paul Avatar answered Nov 19 '22 07:11

A Paul


Use

new XStream(new StaxDriver())

xpp and xmlpull are very old codebases

with non-default constructor you could avoid those 2 jars

like image 11
Kalpesh Soni Avatar answered Nov 19 '22 07:11

Kalpesh Soni


You can too use :

new XSteam(new DomDriver())

The difference with StaxDriver is the output of convert objet to xml.

Output DomDriver :

<person>
  <firstname>Joe</firstname>
  <lastname>Walnes</lastname>
  <phone>
    <code>123</code>
    <number>1234-456</number>
  </phone>
  <fax>
    <code>123</code>
    <number>9999-999</number>
  </fax>
</person>

Output StaxDriver :

<?xml version="1.0" ?><person><firstname>Joe</firstname><lastname>Walnes</lastname><phone><code>123</code><number>1234-456</number></phone><fax><code>123</code><number>9999-999</number></fax></person>
like image 1
Boostaut Avatar answered Nov 19 '22 09:11

Boostaut