2017-01-09 7 views
0

からである必要があります。異なるxsdファイルに異なる名前空間を割り当てようとしていて、jaxb2-mavinプラグインを使用して、これらのxsdファイル。jaxb2-mavin-plugin XJBのエラー: 'bindings'要素の名前空間がスキーマの名前空間 '

Mavenは、次のエラーでソースを生成するために失敗します。

<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> 

<?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名前空間ディレクティブの異なる形で試してみました:The namespace of element 'bindings' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'

はここに私の構成です。 Eclipseのコード補完では、バインディングのXMLスキーマをオプションとして見ることができます。そのため、なぜmavenがこのエラーを返すのかわかりません。

+0

プラグインの設定とは何ですか? – teppic

答えて

1

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ゴールのドキュメントで詳しく説明されています。

+0

ありがとう、私は元の問題を修正するxjbSourcesを追加しました。私は今、2つのxsdの間で重複している名前空間が失敗する以前の問題に戻ります。私は、定義済みのパッケージ名を持つXJBがこれの解決策であると考えました。思考? –

+1

同じ名前空間内の要素のクラスを異なるパッケージで生成することはできないため、クラス自体の名前を変更することによって名前の衝突を解決する必要があります(バインディングファイルで行うことができます)。 – teppic

+0

ありがとうございます。バインディングファイルで指定されている別のパッケージで作成されることによって重複が処理されるという印象を受けました。 –