Jibx Maven插件:在不同的构建执行中转换时,模式之间的交叉引用

时间:2012-08-10 22:16:01

标签: java maven jibx

我使用jibx Maven插件将一些xsds转换为Java源代码。在模式A中,有一个对模式B中定义的类型的引用。之前,我使用了这个pom.xml配置,一切正常:

<plugin>
    <groupId>org.jibx</groupId>
    <artifactId>jibx-maven-plugin</artifactId>
    <version>1.2.3</version>
    <configuration>
        <schemaLocation>${basedir}/resources/oxm/schemas</schemaLocation>
        <schemaBindingDirectory>${basedir}/src/java</schemaBindingDirectory>
        <includeSchemas>
            <includeSchema>schemaA.xsd</includeSchema>
            <includeSchema>schemaB.xsd</includeSchema>
            <includeSchema>schemaC.xsd</includeSchema>
        </includeSchemas>
        <verbose>true</verbose>
     </configuration>
 </plugin>

输入模式A类似于:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="myApp.com/schema/schemaA"targetNamespace="http://myApp.com/schema/schemaA" xmlns:rsType="http://myApp.com/schema/schemaB">
<xs:import schemaLocation="schemaB.xsd" namespace="http://myApp.com/schema/schemaB" />
<xs:complexType name="classAType">
    <xs:sequence>
        <xs:element name="objB" type="rsType:classBType" />
    </xs:sequence>
    <xs:attribute name="foo" type="xs:int" />
 </xs:complexType>

输入模式B具有类似于classBType定义的代码。

以前的Java源代码输出类似于:

class classA
{
    classB objB;
    int foo;
}

最近,我将pom.xml中不同构建执行中的模式转换分开,以便能够为它们定义不同的目标包。我的新pom.xml是:

<plugin>
    <groupId>org.jibx</groupId>
    <artifactId>jibx-maven-plugin</artifactId>
    <version>1.2.3</version>
    <configuration>
        <schemaLocation>${basedir}/resources/oxm/schemas</schemaLocation>
        <schemaBindingDirectory>${basedir}/src/java</schemaBindingDirectory>
        <verbose>true</verbose>
     </configuration>
     <executions>
         <execution>
             <id>schemaCodegenA</id>
             <goals>
                 <goal>schema-codegen</goal>
             </goals>
             <configuration>
                 <includeSchemas>
                     <includeSchema>schemaA.xsd</includeSchema>
                  </includeSchemas>
                  <options>
                      <package>com.myApp.jibxgenerated.schema.resource</package>
                  </options>
              </configuration>
          </execution>

(...每组模式执行一次)      

现在Java源输出是:

class classA
{
    // all properties of class B here
    int classBattrib1;
    int classBattrib2;
    int classBattribN;
    int foo;
}

这是预期的行为吗?我希望在类A源代码中有classB引用,有没有办法实现这个?

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

user1550682,

实际上,JiBX很容易处理这个案例。您可以将每个模式打包在一个单独的jar中,并使用maven插件轻松引用子模块。

请在此处查看模块化架构的说明: http://jibx.sourceforge.net/maven-jibx-plugin/modular-codegen.html

在这里看一下github中的示例代码: https://github.com/jibx/maven-plugin/tree/master/test-suite/base-binding-test

此示例使用三个简单架构:company - &gt;地址 - &gt;人。有一个简单的测试,marshalls和unmarshalls一些xml。

我希望这有帮助!