mojohaus / jaxb2-maven-plugin

JAXB2 Maven Plugin
https://www.mojohaus.org/jaxb2-maven-plugin/
Apache License 2.0
106 stars 77 forks source link

JAXB SchemaBinding instruction is ignored #104

Open jvissers opened 6 years ago

jvissers commented 6 years ago

I'm migrating a project to Java 9 and we're using external JAXB configuration using .xjb/.jbx files. What I'm seeing is that an external configuration file like this one:

<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jaxb:bindings schemaLocation="../xsd/TaskData.xsd">
        <jaxb:schemaBindings>
            <jaxb:package name="com.common.oxm.taskdata"/>
            <jaxb:nameXmlTransform>
                <jaxb:typeName suffix="XMLType"/>
                <jaxb:elementName suffix="XMLElement"/>
                <jaxb:anonymousTypeName suffix="XMLInnerType"/>
            </jaxb:nameXmlTransform>
        </jaxb:schemaBindings>
    </jaxb:bindings>    
</jaxb:bindings>

Does not produce packages, classes as have been specified. What instead happens is that the package names and class names are only derived from information that is contained in the XSDs. As such the instructions in the binding file seem to be ignored. Mind you: when I make a syntax error on purpose in the binding file, the plugin actually does fail indicating that there is a problem in the binding file.

Am I missing something?

jvissers commented 6 years ago

Hmmm - seems to have been reported on a different plugin as well: https://github.com/highsource/maven-jaxb2-plugin/issues/120

jvissers commented 6 years ago

Tried with this copied test


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
            jaxb:version="2.0" targetNamespace="http://java9.wtf/maven-jaxb2-plugin/no/pack"
            elementFormDefault="qualified">

    <xsd:annotation>
        <xsd:appinfo>
            <jaxb:schemaBindings>
                <jaxb:package name="wtf.java9.maven_jaxb2_plugin.with.pack"/>
            </jaxb:schemaBindings>
        </xsd:appinfo>
    </xsd:annotation>

    <xsd:complexType name="SimpleClassWithPackage">
        <xsd:sequence>
            <xsd:element name="attribute" type="xsd:string" minOccurs="1" maxOccurs="1">
            </xsd:element>
        </xsd:sequence>
    </xsd:complexType>

</xsd:schema>

This results in a class being generated with a package name derived from the targetNamespace and not from the schemaBinding instruction.

jvissers commented 6 years ago

Even though jaxb:schemaBindings are read, I see when I debug the plugin that this doesn't lead to any registrations of instances of "BISchemaBinding". This subsequently means that in the ClassSelector.getPackage() the lookup to get the configured package for a namespace yields nothing - but the default name created by the NameConverter.

jvissers commented 6 years ago

Further analysis shows that for the above test case the SchemaBindings is registered as a BIXPluginCustomization. It has all of the information as is specified in the xsd:appinfo - but it is created with the wrong type (I think).

jvissers commented 6 years ago

Another interesting link with respect to this issue: https://issues.apache.org/jira/browse/CXF-7055

jvissers commented 6 years ago

FYI: Found that http://cxf.apache.org/cxf-xjc-plugin.html (version 3.2.1) - does honor schemaBindings correctly. So these guys apparently have fixed the issue.

lennartj commented 6 years ago

Feel free to supply a Pull Request with an integration test here.

ostecke commented 5 years ago

I encountered this bug today. With the upcoming end-of-life of Java 8, I think this bug might become a bit more critical.