在创建 JAXB 对象时,如何使用 xsd 模式的自定义包名称及其所有依赖模式?

时间:2021-01-13 15:51:09

标签: xsd jaxb maven-jaxb2-plugin jaxb2-maven-plugin

我有一个架构 MainSchema.xsd,我想通过 org.jvnet.jaxb2.maven2.maven-jaxb2-plugin 插件创建其 jaxb 对象。我的主要架构通过 xs:include 元素依赖于其他一些架构,其中一些存在于同一目录中,而其中一些存在于其父目录和子目录中。这些架构在同一文件夹中具有自己的依赖项,以创建层次结构。为了说明,我的架构文件夹结构如下(名称附加依赖项)

DirA
|
|--DirB
|  |
|  |--MainSchemaDependsOnSchemaOne.xsd
|  |--SchemaOneDependsOnSchemaTwo.xsd
|  |--DirC
|     |
|     |--SchemaTwoDependsOnSchemaThree.xsd
|--SchemaThree.xsd

编译器将首先创建所有依赖项的对象,然后创建主模式的对象。我的目标是让所有这些对象都在一个自定义的包名 Ex 中。 com.orgName.projectName

我该怎么做?

我不想在我的 bindings.xjb 中指定每个架构文件来执行此操作。

pom.xml

    <build>
    <plugins>
        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>${org.jvnet.jaxb2.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- Where .xsd schemas are stored -->
                <schemaDirectory>${basedir}/src/schemas</schemaDirectory>
                <schemaIncludes>
                    <include>MainSchema.xsd</include>
                </schemaIncludes>
                <bindingDirectory>${basedir}/src/binding</bindingDirectory>
                <bindingIncludes>
                    <include>bindings.xjb</include>
                </bindingIncludes>
                

MainSchema.xsd

  <xs:include schemaLocation="SchemaOne.xsd" />

SchemaOne.xsd

<xs:include schemaLocation="./DirC/SchemaTwo.xsd" />

绑定.xjb

        <jaxb:bindings schemaLocation="../schemas/A/B/MainSchema.xsd" node="/xsd:schema">
    <jaxb:schemaBindings>
        <jaxb:package name="com.myOrg.myProj.xml.custompkg_v1"/>
    </jaxb:schemaBindings>
</jaxb:bindings>

如果做不到,看一个有点类似的用例here ,至少可以像答案中提到的那样在每个文件夹的基础上完成吗?一个用于 DirA 的绑定文件,一个用于 DirB .... 绑定文件适用于文件夹中的所有模式,例如

<jaxb:bindings schemaLocation="../schemas/A/*.xsd" node="/xsd:schema">
    <jaxb:schemaBindings>
        <jaxb:package name="com.myOrg.myProj.xml.custompkg_v1"/>
    </jaxb:schemaBindings>
</jaxb:bindings>

0 个答案:

没有答案