2016-11-07 4 views
1

JavaプロジェクトからISAN Restful APIを呼び出したいので、maven-jaxb2-pluginを使用してxsdファイルからJava Beanを生成しようとしています。ここでのXSDは以下のとおりです。XJC - コンパイラがこのクラスのカスタマイズを尊重することができませんでした

私は、論文のファイルをダウンロードし、私のsrc/main/resourcesフォルダにそれらをコピーしてカタログを定義しました。 私はプロジェクトをビルドすると2種類が同じ名前持っているので、私はエラーを取得:

org.xml.sax.SAXParseExceptionpublicId: http://www.isan.org/schema/v1.11/common/language; systemId: http://www.isan.org/schema/v1.11/common/language.xsd; lineNumber: 39; columnNumber: 48; A class/interface with the same name "org.isan.CodingSystemType" is already in use. Use a class customization to resolve this conflict. 
org.xml.sax.SAXParseExceptionpublicId: http://www.isan.org/schema/v1.11/common/country; systemId: http://www.isan.org/schema/v1.11/common/country.xsd; lineNumber: 39; columnNumber: 48; (Relevant to above error) another "CodingSystemType" is generated from here. 

正しいです:

<xs:simpleType name="CodingSystemType"> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="ISO639_2"/> 
      <xs:enumeration value="RFC3066"/> 
     </xs:restriction> 
    </xs:simpleType> 

    <xs:simpleType name="CodingSystemType"> 
     <xs:restriction base="xs:string"> 
      <xs:enumeration value="ISO3166_1"/> 
     </xs:restriction> 
    </xs:simpleType> 
:language.xsdとcountry.xsd両方がCodingSystemType名前付きの型を定義します

提案したように、私はcountry.xsd型のクラスカスタマイズを使用しようとしました。私はのpom.xmlにこのバインディングを追加しました:

<bindings> 
    <binding> 
     <url>http://www.isan.org/schema/v1.11/common/country.xjb</url> 
    </binding> 
</bindings> 

XJCファイル:今

<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:annox="http://annox.dev.java.net" 
    xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix"> 
    <bindings schemaLocation="http://www.isan.org/schema/v1.11/common/country.xsd"> 

     <bindings node="//xs:simpleType[@name='CodingSystemType']"> 
     <class name="CountryCodingSystemType" /> 
     </bindings> 

    </bindings> 
</bindings> 

、私は私がに対処することはできません別のエラーを取得:

[ERROR] Error while parsing schema(s).Location [ http://www.isan.org/schema/v1.11/common/country.xjb{7,58}]. 
com.sun.istack.SAXParseException2; systemId: http://www.isan.org/schema/v1.11/common/country.xjb; lineNumber: 7; columnNumber: 58; compiler was unable to honor this class customization. It is attached to a wrong place, or its inconsistent with other bindings. 
[ERROR] Error while parsing schema(s).Location [ http://www.isan.org/schema/v1.11/common/country.xsd{39,48}]. 
com.sun.istack.SAXParseException2; systemId: http://www.isan.org/schema/v1.11/common/country.xsd; lineNumber: 39; columnNumber: 48; (the above customization is attached to the following location in the schema) 
+0

あなたの問題に関連しているかどうかは不明ですが、通常はパッケージをクラス名のバインディングに含めないでください: 'name =" CountryCodingSystemType "'。 – Rob

+0

パッケージがないと同じ問題が発生します。しかし、あなたはそれが正しくないと言って私の投稿を編集しました。 – jaudo

答えて

1

:関連の質問を参照してください。

私が気づいたのは、これらの2つの単純なタイプは実際には異なる名前空間に属していることです。したがって、実際には、最初は同じパッケージで生成されるべきではありません。

generatePackageを入力して、org.isanをターゲットパッケージに指定するといいでしょう。だからあなたのすべての名前空間はかなり悪い1つのパッケージになります。 JAXBは、名前空間ごとに1つのパッケージがある場合に最適です。あなたがしなければそれは変になるでしょう。

だから私は、一般的に代わりjaxb:packageを使用し、generatePackageの使用を思いとどまら:

<bindings schemaLocation="http://www.isan.org/schema/v1.11/common/country.xsd"> 
    <schemaBindings> 
     <package name="org.isan.schema.v1_11.common.country"/> 
    </schemaBindings> 
    </bindings> 

私はまた、メジャー/マイナースキーマのバージョンにパッケージ名を使用してお勧めします。後で複数のスキーマバージョンを同時にサポートする必要があるかもしれません。

+0

generatePackageの削除も機能します。それはより良い解決策のように見え、私はもはや束縛を必要としません – jaudo

2

をお試しください
<bindings node="//xs:simpleType[@name='CodingSystemType']"> 
    <typesafeEnumClass name="CountryCodingSystemType" /> 
</bindings> 

代わりに

私はXJCがカスタマイズの列挙型と通常のクラスの違いになると思います。それはあなたのスキーマのコンパイルに関するさまざまな話題にかかるので、私は別の答えを追加します

関連する問題