当前位置: 代码迷 >> java >> 如何忽略特定模式在生成的jar中的导入模式中的类
  详细解决方案

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

热度:93   发布时间:2023-07-31 11:29:42.0

我有一个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>

此显示了如何完成此操作,但我无法对其进行配置。如果我需要添加剧集,则需要在同一版本中生成它(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对此存在一些问题)。 我经常在构建的后期处理步骤中将其删除。

我通常建议将用于此类事情。 这是的 。

免责声明:我是

  相关解决方案