maven-jibxcodegen-存储binding.xml

maven-jibxcodegen-存储binding.xml,binding,maven,jibx,codegen,Binding,Maven,Jibx,Codegen,我正在使用maven构建一个jar,其中包含使用jibx从模式文件生成的代码。要做到这一点,我将使用jibx maven插件和schema codegen目标。我想将生成的binding.xml文件作为结果maven jar的一部分。是否有任何方法可以指导jar创建以包括生成的binding.xml 目前正在使用: <plugin> <groupId>org.jibx</groupId> <artifactId>jibx-maven

我正在使用maven构建一个jar,其中包含使用jibx从模式文件生成的代码。要做到这一点,我将使用jibx maven插件和schema codegen目标。我想将生成的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>

org.jibx
jibxmaven插件
1.2.3
src/main/jibx
dataoneTypes.xsd
org.dataone.ns.service.types.v1
模式代码生成
您始终可以使用将文件(集合)复制到目标/类

确保:

  • 您将jibx插件附加到
    包之前的一个阶段
    ——最好是
    生成资源
  • 您将antrun执行附加到相同或更高版本,但同样是在
    之前-最好是
    生成资源
    处理资源
  • 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>
...
...
<goals>
     <goal>schema-codegen</goal>
</goals>
<configuration>
...
     <targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
。。。
org.apache.maven.plugins
maven antrun插件
1.6
产生资源
跑
...
您始终可以使用将文件(集合)复制到目标/类

确保:

  • 您将jibx插件附加到
    包之前的一个阶段
    ——最好是
    生成资源
  • 您将antrun执行附加到相同或更高版本,但同样是在
    之前-最好是
    生成资源
    处理资源
  • 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>
...
...
<goals>
     <goal>schema-codegen</goal>
</goals>
<configuration>
...
     <targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
。。。
org.apache.maven.plugins
maven antrun插件
1.6
产生资源
跑
...

您可以在目标目录中创建binding.xml,并将其放置在jar中,如下所示:

...
<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>
...
...
<goals>
     <goal>schema-codegen</goal>
</goals>
<configuration>
...
     <targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
。。。
模式代码生成
...
目标/资源
...
...

绑定代码时,您可以使用referethisdirectory和
标记您可以在目标目录中创建binding.xml,您希望它像这样放置在jar中:

...
<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>
...
...
<goals>
     <goal>schema-codegen</goal>
</goals>
<configuration>
...
     <targetDirectory>target/resources</targetDirectory>
...
</configuration>
...
。。。
模式代码生成
...
目标/资源
...
...
绑定代码时,您可以使用带有
标记的“引用此目录”

David

好!!虽然不需要包含binding.xml文件,但这是一种良好的做法。新的jibx maven插件可以在以后创建基于原始模式的新绑定时使用此文件。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>

4.0.0
org.dataone.ns.service
org.dataone.ns.service.types.v1
0.0.1
捆
org.jibx
jibxmaven插件
1.2.3
从模式生成java代码
模式代码生成
src/main/jibx
dataoneTypes.xsd
org.dataone.ns.service.types.v1
编译绑定
绑定
目标/生成源
binding.xml
org.apache.felix
maven捆绑插件
真的
META-INF/binding.xml=${basedir}/target/generated sources/binding.xml
org.dataone.ns.service.types.v1.*;版本=${project.version}
org.jibx
jibx运行
1.2.3
org.jibx
jibx附加服务
1.2.3
看看您的jar文件。您的类、binding.xml文件和OSGi清单条目都在那里

唐·科利 jibx maven插件作者David

好!!虽然不需要包含binding.xml文件,但这是一种良好的做法。新的jibx maven插件可以在以后创建基于原始模式的新绑定时使用此文件。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>

4.0.0
org.dataone.ns.service
org.dataone.ns.service.types.v1
0.0.1
捆
org.jibx
jibxmaven插件
1.2.3
从模式生成java代码