如何在为特定模式生成的 jar 中忽略导入模式中的 类

How to ignore classes from imported schemas in the generated jar for a particular schema

我有一个 xsd 文件 a.xsd,它导入另一个 xsd b.xsd。我想从 a.xsd 创建一个包含所有 类 的 jar,但忽略从 b.xsd 生成的 类。我的pom文件如下。

<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>com.personal.proj</groupId>
    <artifactId>schema-model</artifactId>
    <version>1.0.0</version>
    <name>SchemaModel</name>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.12.3</version>
                <executions>
                    <execution>
                        <id>id</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <schemaDirectory>src/main/xsd</schemaDirectory>
                            <schemaIncludes>
                                <include>a.xsd</include>
                            </schemaIncludes>
                            <schemaExcludes>
                                <exclude>b.xsd</exclude>
                            </schemaExcludes>
                            <forceRegenerate>true</forceRegenerate>
                            <removeOldOutput>true</removeOldOutput>
                            <bindingDirectory>src/main/xsd</bindingDirectory>
                            <bindingIncludes>
                                <include>schema.xjb</include>
                            </bindingIncludes>
                            <generateDirectory>${project.build.directory}/generated-sources</generateDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我的 schema.xjb 文件是

<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
jxb:version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="a.xsd" node="/xs:schema">
    <jxb:schemaBindings>
        <jxb:package name="com.a.model" />
    </jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="b.xsd" node="/xs:schema">
    <jxb:schemaBindings>
        <jxb:package name="com.b.model" />
    </jxb:schemaBindings>
</jxb:bindings>

这个 link 展示了如何做到这一点,但我无法配置 it.If 我需要添加剧集,我需要生成它 (b.episode)构建并使用它来生成 a.jar

b.xsd 绑定上使用 map="false"

<jxb:bindings schemaLocation="b.xsd" node="/xs:schema">
    <jxb:schemaBindings map="false">
        <jxb:package name="com.b.model" />
    </jxb:schemaBindings>
</jxb:bindings>

仍有一些 类 可能会生成(XJC 在这方面有一些问题)。我经常在构建的 post 处理步骤中删除它们。

我一般推荐使用episodes for such things. Here's a test project for episodes

免责声明:我是 .

的作者