6

私はmaven jaxb2プラグインを使用して、jar内のスキーマから構築されたJavaクラスを生成しています。ただし、バインディング ファイルからこれらのスキーマを正しく検索する方法がわかりません。jar からスキーマを抽出し、バインディングと同じディレクトリにドロップすれば、すべて問題ありません。ただし、これは実用的な長期的な解決策ではありません。

pom.xml:

<plugin>
 <groupId>org.jvnet.jaxb2.maven2</groupId>
  <artifactId>maven-jaxb2-plugin</artifactId>
  <version>0.8.1</version>
  <executions>
    <execution>
     <goals>
      <goal>generate</goal>
     </goals>
    </execution>
   </executions>
   <configuration>
    <schemas>
     <schema>
      <dependencyResource>
       <groupId>com.test</groupId>
       <artifactId>schemas</artifactId>
       <version>1.10-SNAPSHOT</version>
       <resource>schemas/schema.xsd</resource>
      </dependencyResource>
     </schema>
    </schemas>              
    <bindingDirectory>bindings</bindingDirectory>
    <generatePackage>test.package</generatePackage>
    <bindingIncludes>
     <include>*.xml</include>
    </bindingIncludes>
    <extension>true</extension>
   </configuration>
  </plugin>

bindings.xml:

<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
 xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb ./bindingschema_2_1.xsd"
 version="2.1">

<jxb:bindings schemaLocation="classpath:/schemas/schema.xsd" node="/xs:schema">
  <jxb:bindings node="//xs:complexType[@name='AbstractChangeable']">
   <jxb:class implClass="com.test.AbstractEntity" />
  </jxb:bindings>
</jxb:bindings>
4

3 に答える 3

6

maven-dependency-plugin:unpackを使用してからポイントmaven-jaxb2-pluginする必要がありますoutputDirectory。この場合、バインディングファイルで次のように言う必要がありますschemaLocation="../target/schemas/schema.xsd"

于 2012-02-29T22:10:16.080 に答える
5

ここで働きたいのは、次のようなものです。

<jaxb:bindings schemaLocation="maven:org.jvnet.jaxb2.maven2:maven-jaxb2-plugin-tests-po!/purchaseorder.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
        <jaxb:package name="org.jvnet.jaxb2.maven2.tests.po"/>
    </jaxb:schemaBindings>      
</jaxb:bindings>

しかし、現時点ではそうではありません。問題を報告してください。修正を試みます。

現在機能しているのは、SCD ベースのバインドです。

<jaxb:bindings scd="x-schema::po" xmlns:po="urn:po">
    <jaxb:schemaBindings>
        <jaxb:package name="org.jvnet.jaxb2.maven2.tests.po"/>
    </jaxb:schemaBindings>      
</jaxb:bindings>

したがって、特定のスキーマの場所に基づいて実際にバインドする必要はなく、名前空間 URI に基づいてバインドできます。これは理論的には優れています。

実際には、SCD バインディングが常に確実に機能するとは限らないという経験があります。

アップデート

JAXB での SCD の使用に関する詳細については、このリンクを参照してください。

于 2012-03-01T21:37:30.843 に答える