[英]Error in jaxb2-maven-plugin XJB: The namespace of element 'bindings' must be from the schema namespace'
我試圖為不同的 xsd 文件分配不同的名稱空間,並使用 jaxb2-maven 插件來構建由這些 xsd 文件定義的工件。
Maven 無法生成源並出現以下錯誤: The namespace of element 'bindings' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'
這是我的配置:
<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>
我嘗試過不同形式的 XML 命名空間指令。 在 Eclipse 代碼完成中,我可以看到綁定 XML 模式作為一個選項,所以我不知道為什么 maven 會返回這個錯誤。
maven jaxb2 插件正在其源路徑中查找您的綁定文件,並假設它是一個 xsd 文件。 您必須通過移動它、更新 xsd/xjb 源路徑或添加排除過濾器來排除它。
最簡單的選擇可能是更新插件配置中的路徑:
<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>
您的綁定文件也存在問題:您需要映射您在node
屬性中使用的命名空間前綴。 將xmlns:xsd="http://www.w3.org/2001/XMLSchema"
到根元素。
jaxb2:xjc目標的文檔中詳細介紹了配置選項。
我遇到了相同的錯誤消息並嘗試了@teppic 建議的解決方案,但不幸的是沒有幫助。
我發現綁定文件和 XSD 文件共享相同的名稱會導致相同的錯誤消息! 我有這樣的事情:
示例.xjb 和示例.xsd
將 .xjb 文件重命名為 example-binding.xjb 后,一切都對我有用!
希望這對 2020 年有所幫助 ^^
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.