kdg*_*ill 7 netbeans module export jaxb marshalling
当我试图在netbeans模块中运行JAXB marshaller时,它们似乎是个问题.最初我认为这是节点的实施,所以我花了几天时间重新组织一切,但我还是收到了奇怪的错误信息
javax.xml.bind.JAXBException: ClassCastException: attempting to cast jar:file:/C:/Program%20Files/jmonkeyplatform/ide/modules/ext/jaxb/api/jaxb-api.jar!/javax/xml/bind/JAXBContext.class to jar:file:/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/rt.jar!/javax/xml/bind/JAXBContext.class. Please make sure that you are specifying the proper ClassLoader.
at javax.xml.bind.ContextFinder.handleClassCastException(ContextFinder.java:96)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:205)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
at com.spectre.util.JAXBImporterExporter.write(JAXBImporterExporter.java:63)
Run Code Online (Sandbox Code Playgroud)
我不确定问题是导入器/导出器似乎在正常项目中工作,导入器在解析文件时似乎工作正常,但导出似乎导致问题.我用来导出的方法是
public static <T> void write(T savable, Class<T> type,Object path) {
try {
JAXBContext jc = JAXBContext.newInstance(type);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
if(path instanceof File)
marshaller.marshal(savable, (File)path);
else if(path instanceof OutputStream){
marshaller.marshal(savable, (OutputStream)path);
}else throw new NoSuchMethodException("The Field Path must be of either type File or OutputStream");
} catch (NoSuchMethodException ex) {
Exceptions.printStackTrace(ex);
} catch (JAXBException ex) {
Exceptions.printStackTrace(ex);
}
}
Run Code Online (Sandbox Code Playgroud)
任何协助表示赞赏
| 归档时间: |
|
| 查看次数: |
2661 次 |
| 最近记录: |