我正在使用 Ant,现在我需要生成应该实现 java.io.Serialized
接口(interface)的类。我使用绑定(bind)文件来生成可序列化的类,并使用 dtd 来定义类。但是,xjc 抛出错误 [xjc] [ERROR] cvc-elt.1: Cannot find the statements of element 'jxb:bindings'。我将绑定(bind)文件作为参数传递给 xjc 任务:
<arg value="-b"/>
<arg file="../WebContent/DTD/bindings.xjb"/>
这是我的绑定(bind)文件
<jxb:bindings
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc"
version="2.0">
<jxb:globalBindings>
<xjc:serializable/>
</jxb:globalBindings>
</jxb:bindings>
请指点出路
最佳答案
您的问题是您正在使用 DTD。 DTD 来自史前时代,绑定(bind)文件有 different format那时。
尝试如下:
<xml-java-binding-schema xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
<xjc:serializable/>
</xml-java-binding-schema>
这是一个DTD example from the RI .
祝你好运。 并切换到 XSD。 :)
关于java - JaxB 无法序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25932656/