我使用 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 引用,有什么方法可以实现吗?
提前感谢您的帮助。