7
votes

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 ]

3

3 Answers

5
votes

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

2
votes

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.

1
votes

Assumed that you are using Eclipse or a derivative (websphere studio, jDeveloper, Spring Tools Suite, ...). If not, you may use the JDK 'xjc' command line tool, else the Maven Plug-in JAXB2)

You have to explicitly configure JAXB for the project (different projects may bear different configs to make things simple!)

In recent Eclipse version (4.4+) follow these steps:

  • ensure the Eclipse Web Tools platform is installed in Eclipse
  • apply the JAXB facet to your Eclipse project containing the .xsd schemas to transform into jaxb classes; right-click project > properties > Project Facets > JAXB; further configuration is available and lets you select which library supplies the JAXB implementation (recent JRE has it) as well as the JAXB version. > OK > Apply.
  • select the .xsd file at stake, right-click > generate > JAXB classes ... at minimum supply a package name (e.g. draw it from the XSD namespace) > Finish
  • the Eclipse console view provides feedback on generated files