1

私はmavenを使用して、jibxを使用してスキーマファイルから生成されたコードを含むjarを構築しています。これを行うために、schema-codegen ゴールで jibx-maven-plugin を使用しています。生成された binding.xml ファイルを、結果の maven jar の一部として含めたいと考えています。jar の作成に、生成された binding.xml を含めるように指示する方法はありますか

現在使用中:

<plugin>
    <groupId>org.jibx</groupId>
    <artifactId>jibx-maven-plugin</artifactId>
    <version>1.2.3</version>
    <configuration>
        <schemaLocation>src/main/jibx</schemaLocation>
        <includeSchemas>
            <includeSchema>dataoneTypes.xsd</includeSchema>
        </includeSchemas>
        <options>
            <package>org.dataone.ns.service.types.v1</package>
        </options>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>schema-codegen</goal>
            </goals>
        </execution>

    </executions>
</plugin>
4

4 に答える 4

1

デビッド、

良い!binding.xmlファイルを含める必要はありませんが、それは良い習慣です。新しいjibx-maven-pluginは、後で元のスキーマに基づく新しいバインディングを作成するときにこのファイルを使用できます。JiBXソースリポジトリにはたくさんの例があります。

JiBXはOSGiに対応しているため、jarファイルを作成するときにOSGiマニフェストを追加することもお勧めします。これにより、binding.xmlファイルを含めることも簡単になります。OSGiを使用しなくても、jarは正常に機能します。プロジェクトファイルは次のようになります。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.dataone.ns.service</groupId>
    <artifactId>org.dataone.ns.service.types.v1</artifactId>
    <version>0.0.1</version>
    <packaging>bundle</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jibx</groupId>
                <artifactId>jibx-maven-plugin</artifactId>
                <version>1.2.3</version>

                <executions>
                    <execution>
                        <id>generate-java-code-from-schema</id>
                        <goals>
                            <goal>schema-codegen</goal>
                        </goals>
                        <configuration>
                            <schemaLocation>src/main/jibx</schemaLocation>
                            <includeSchemas>
                                <includeSchema>dataoneTypes.xsd</includeSchema>
                            </includeSchemas>
                            <options>
                                <package>org.dataone.ns.service.types.v1</package>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <id>compile-binding</id>
                        <goals>
                            <goal>bind</goal>
                        </goals>
                        <configuration>
                            <schemaBindingDirectory>target/generated-sources</schemaBindingDirectory>
                            <includes>
                                <include>binding.xml</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Include-Resource>META-INF/binding.xml=${basedir}/target/generated-sources/binding.xml</Include-Resource>
                        <Export-Package>org.dataone.ns.service.types.v1.*;version=${project.version}</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-run</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-extras</artifactId>
            <version>1.2.3</version>
        </dependency>
    </dependencies>

</project>

jarファイルを見てください。クラス、binding.xmlファイル、およびOSGiマニフェストエントリがあります。

DonCorleyjibx-maven-プラグイン作成者

于 2011-09-20T18:04:30.580 に答える
0

いつでもmaven-antrun-pluginを使用して、ファイル (セット) をターゲット/クラスにコピーできます。

次のことを確認してください。

  • 前に jibxプラグインをフェーズにアタッチしますpackage-最良の方法はgenerate-resources
  • antrun の実行を同じかそれ以降にアタッチしますが、これも前に package- 最良の方法はgenerate-resourcesまたはprocess-resources
  • jibx プラグインの宣言は、antrun の宣言より前に行われます

次に、次のようなものを使用できます。

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
      <execution>
         <phase>generate-resources</phase>
         <goals>
           <goal>run</goal>
         </goals>
         <configuration>
           <tasks>
             <copy file="${project.build.directory}/PATH/TO/binding.xml" todir="${project.build.outputDirectory}/PATH/IN/JAR/"/>
           </tasks>
         </configuration>
       </execution>
     </executions>
</plugin>
...
于 2011-08-18T19:56:42.117 に答える
0

build-helper-maven-plugin のadd-resourceゴールを使用して実行できます。

例:

<build>
    <plugins>
        <plugin>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-maven-plugin</artifactId>
            <version>1.2.3</version>
            <executions>
                <execution>
                    <id>generate-java-code-from-schema</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>schema-codegen</goal>
                    </goals>
                    <configuration>
                        <schemaLocation>src/main/resources</schemaLocation>
                        <includeSchemas>
                            <includeSchema>foobar.xsd</includeSchema>
                        </includeSchemas>
                    </configuration>
                </execution>
                <execution>
                    <id>compile-binding</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>bind</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>add-resource</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>add-resource</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>${project.build.directory}/generated-sources</directory>
                                <includes>
                                    <include>binding.xml</include>
                                </includes>
                                <targetPath>JiBX</targetPath>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

次の jar に binding.xml ファイルがあります。

JiBX/binding.xml
于 2012-02-03T13:41:50.223 に答える
0

次のように、jar に配置するターゲット ディレクトリに binding.xml を作成できます。

...
<goals>
     <goal>schema-codegen</goal>
</goals>
<configuration>
...
     <targetDirectory>target/resources</targetDirectory>
...
</configuration>
...

コードをバインドするときは、このディレクトリへの参照<bindingDirectory>タグを使用できます

于 2011-09-06T13:09:29.830 に答える