How to use xstream fro xml serialization in eclipse
Solution 1
- Extract the zip file to a directory (e.g.
C:\Program Files\XStream
) - In eclipse, right-click on your project and select
Build Path > Configure Build Path...
- Select
Libraries
tab - Select
Add External Jars..
- Navigate to the
lib
folder of your XStream download and select the jar(s) to be added - Select
Open
- Select
OK
And here's the Two Minute Tutorial on how to use XStream.
Solution 2
Got this exception, then I download kxml2-min-2.3.0.jar and add it as a library and now it works (using xstream 1.4.4.jar)
Solution 3
You need to unzip the .zip file to get at the .jar file, which you put on your classpath for your project in eclipse (Google if you don't know how to add third party library .jars to your project classpath in Eclipse).
Once it is added to your project's classpath, you use the classes contained within it as you would any other classes, and the documentation on the XStream website tells you how to use them.
Good choice by the way, XStream is great!
Solution 4
You can add this library:
<dependency>
<groupId>xmlpull</groupId>
<artifactId>xmlpull</artifactId>
<version>1.1.3.1</version>
</dependency>
Solution 5
I had added the two libraries: dom4j-2.0.0-ALPHA-2.jar
and xstream-1.4.7.jar
and the same issue were displayed. After adding the kxml2-min-2.3.0.jar
the issue is not happening.
Daniel
I am a software engineer living in Atlanta, Georgia. I am looking forward to my Mi.Yodeya reputation exceeding my Stack Overflow reputation, because I think that will mean that I am no longer a nerd. My Mi.Yodeya reputation has finally exceeded my SO reputation! I'm not a nerd anymore.
Updated on June 09, 2022Comments
-
Daniel almost 2 years
I am having some trouble figuring out how to download and use xstream in eclipse. When I download the binary distribution from the website, I get a zip file. Where should I extract it, and how do I use it?
Edit:
OK, I have added it to my build path, but now when I try to use XStream to serialize an
ArrayList<Earmark>
whereEarmark
is a class that I have defined, I get the following error message:Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException at com.thoughtworks.xstream.XStream.<init>(XStream.java:334) at examples.TestEarmarkExtractor.SerializeEarmarks(TestEarmarkExtractor.java:19) at examples.TestEarmarkExtractor.main(TestEarmarkExtractor.java:48) Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) 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) ... 3 more
Update: The error is occurring before I try the serialization. It occurs on the line
XStream xs = new XStream();