-->

JIBX Maven插件:模式之间的交叉参考时它们被转换在不同的构建处决(Jibx Maven pl

2019-10-17 03:10发布

我使用的JiBX Maven插件一些的XSD到Java源代码的转换。 在一个模式的,还有就是在架构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;
}

这是预期的行为? 我想有CLASSB参考回到了A类的源代码,有没有什么办法来实现这一目标?

在此先感谢您的帮助。

Answer 1:

user1550682,

其实JiBX的很轻松地处理这种情况。 你可以打包在单独的罐中的每个模式,并方便地引用使用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

此示例使用三个简单的模式:公司 - >地址 - >人。 并进行了简单的测试,马绍尔群岛和一些解组XML。

我希望这有帮助!



文章来源: Jibx Maven plugin: cross-reference among schemas when they are converted in different build executions
标签: java maven jibx