使用Xstream,需要澄清

时间:2012-02-27 16:27:00

标签: java classpath xstream

考虑一个简单的Xsctream示例来创建Bean的JSON:

Bean bean = new Bean();
bean.addNames("John", "Doe");
bean.addNames("Jane", "Doe");

XStream xstream = new XStream(new JettisonMappedXmlDriver());    
xstream.setMode(XStream.NO_REFERENCES);

System.out.println(xstream.toXML(bean));

结果

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jettison/mapped/Configuration
    at com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver.<init>(JettisonMappedXmlDriver.java:55)
    at Main.main(Main.java:12)

请注意库已导入,因为它们应该

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;

包括适当的罐子

enter image description here

1 个答案:

答案 0 :(得分:8)

你需要来自codehaus的jettison.jar click this link