Udit Mishra
Udit Mishra

Reputation: 140

JaxB can not Serialize

I am using Ant, now I need to generate classes which should implement the java.io.Serializable interface. I am using a binding file to generate serializable classes, and I am using a dtd to define the classes. But, xjc throws the error [xjc] [ERROR] cvc-elt.1: Cannot find the declaration of element 'jxb:bindings'. I am passing the binding file as an argument to xjc task :

        <arg value="-b"/>
        <arg file="../WebContent/DTD/bindings.xjb"/>

Here is my binding file

<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>

Kindly suggest the way out

Upvotes: 1

Views: 587

Answers (1)

lexicore
lexicore

Reputation: 43709

Your problem is that you're using a DTD. DTD comes from the prehistoric times and bindings file had a different format back then.

Try something like:

<xml-java-binding-schema xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
  <xjc:serializable/>
</xml-java-binding-schema>

Here's a DTD example from the RI.

Good luck. And switch to XSD. :)

Upvotes: 1

Related Questions