Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use xstream fro xml serialization in eclipse

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> where Earmark 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();
like image 841
Daniel Avatar asked Dec 10 '22 05:12

Daniel


1 Answers

  1. Extract the zip file to a directory (e.g. C:\Program Files\XStream)
  2. In eclipse, right-click on your project and select Build Path > Configure Build Path...
  3. Select Libraries tab
  4. Select Add External Jars..
  5. Navigate to the lib folder of your XStream download and select the jar(s) to be added
  6. Select Open
  7. Select OK

And here's the Two Minute Tutorial on how to use XStream.

like image 146
mre Avatar answered Jan 02 '23 00:01

mre