Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xjc fails to generate classes when using bindings

Tags:

java

jaxb

This used to work with all previous versions of JAXB. I've upgraded to version 2.2.7 of JAXB and now xjc throws the following:

java.lang.AssertionError: javax.xml.bind.JAXBException - with linked exception: [com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
com.sun.xml.bind.api.impl.NameConverter is an interface, and JAXB can't handle interfaces. this problem is related to the following location: at com.sun.xml.bind.api.impl.NameConverter at public com.sun.xml.bind.api.impl.NameConverter com.sun.tools.xjc.reader.xmlschema.bindinfo.BIGlobalBinding.nameConverter at com.sun.tools.xjc.reader.xmlschema.bindinfo.BIGlobalBinding ]

like image 805
Alex Avatar asked Mar 26 '14 19:03

Alex


People also ask

How do you use XJC generated classes?

Open a command prompt. Run the JAXB schema compiler, xjc command from the directory where the schema file is located. The xjc schema compiler tool is located in the app_server_root \bin\ directory. Use the generated JAXB objects within a Java application to manipulate XML content through the generated JAXB classes.

What is JAXB XJC jar?

JAXB Binding Compiler. Contains source code needed for binding customization files into java sources. In other words: the *tool* to generate java classes for the given xml representation. License.


2 Answers

As of jaxb 2.2.7 they have split the jaxb libraries into several components. xjc is now decoupled from any particular jaxb runtime. To fix this issue, ensure a jaxb runtime is made available on the classpath when executing xjc. Details can be found on their release notes here: https://jaxb.java.net/nonav/2.2.7/docs/release-documentation.html#a-2-2-7

The reference implementation can be found on maven central with the following coordinate: com.sun.xml.bind:jaxb-impl:2.2.7

like image 189
Alex Avatar answered Oct 18 '22 02:10

Alex


As the whole JAXB project now moved from https://github.com/javaee/jaxb-v2 to https://github.com/eclipse-ee4j/jaxb-ri including the Maven dependencies, I updated my pom.xml from

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-xjc</artifactId>
        <version>${jaxb-xjc.version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>${jaxb.version}</version>
    </dependency>

to

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-xjc</artifactId>
        <version>${jaxb-xjc.version}</version>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>${jaxb.version}</version>
    </dependency>

This helped me at least with a similar issue.

like image 43
jonashackt Avatar answered Oct 18 '22 03:10

jonashackt