Reputation: 5234
I am attempting to assign different name spaces to different xsd files and use jaxb2-maven plugin to build the artifacts defined by these xsd files.
Maven fails to generate the source with the following error: The namespace of element 'bindings' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'
Here is my configuration:
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb
http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<jaxb:bindings schemaLocation="xsd/TheRequest.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.package.request" />
</jaxb:schemaBindings>
</jaxb:bindings>
<jaxb:bindings schemaLocation="xsd/TheResponse.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:package name="com.package.response" />
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://company.services.com"
xmlns:tns="http://company.services.com"
elementFormDefault="unqualified">
<xsd:complexType name="FindSomething">
<xsd:sequence>
<xsd:element name="TestMode" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="Channel" type="xsd:string" maxOccurs="1" minOccurs="1"/>
<xsd:element name="UserId" type="xsd:string" maxOccurs="1" minOccurs="1"/>
<xsd:element name="Role" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="Format" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="OrgId" type="xsd:string" maxOccurs="1" minOccurs="1"/>
<xsd:element name="TransactionId" type="xsd:string" maxOccurs="1" minOccurs="1"/>
<xsd:element name="Timeout" type="xsd:long" maxOccurs="1" minOccurs="0"/>
<xsd:element name="RequestSegments" type="tns:RequestSegments" maxOccurs="1" minOccurs="0"/>
<xsd:element name="VerifyUserType" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="VerifyUserAccess" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="IncludeFamily" type="xsd:string" minOccurs="0" maxOccurs="1"/>
<xsd:element name="AsOfDate" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="ActiveOnly" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="SearchType" type="xsd:string" maxOccurs="1" minOccurs="0"/>
<xsd:element name="SearchCriteria" type="tns:SearchCriteria" maxOccurs="1" minOccurs="0"/>
<xsd:element name="AccessPrivileges" type="tns:AccessPrivileges" maxOccurs="1" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType></xsd:schema>
I have tried with different forms of XML namespace directives. In Eclipse code completion, I can see the bindings XML schema as an option so I don't know why maven is returning this error.
Upvotes: 2
Views: 7851
Reputation: 445
I ran into the same error message and tried the solution suggested by @teppic, which unfortunately did not help.
I found out that having the binding file and the XSD file sharing the same name is causing the same error message! I had something like this:
example.xjb and examle.xsd
After renaming the .xjb file to example-binding.xjb everything worked for me!
Hope this helps in 2020 ^^
Upvotes: 1
Reputation: 7286
The maven jaxb2 plugin is finding your binding file in its source path and assuming that it is an xsd file. You'll have to exclude it, either by moving it, updating your xsd/xjb source paths, or by adding an exclude filter.
The easiest option is probably to update the paths in the plugin config:
<configuration>
<sources>
<!-- only xsd files under here -->
<source>src/main/xjb/xsd</source>
</sources>
<xjbSources>
<!-- specify binding file explicitly -->
<xjbSource>src/main/xjb/bindings.xjb</xjbSource>
</xjbSources>
</configuration>
There's also a problem with your binding file: you'll need to map the namespace prefix you used in the node
attribute. Add xmlns:xsd="http://www.w3.org/2001/XMLSchema"
to the root element.
The config options are detailed in the doc for the jaxb2:xjc goal.
Upvotes: 6