maven-jaxb2-plugin:解析模式位置时出错,即使xsd和xjb文件位于同一位置

时间:2017-06-12 16:09:46

标签: java maven-3 jaxb2 maven-jaxb2-plugin

我的pom.xml如下所示: -

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <parent>
        <groupId>com.eros</groupId>
        <artifactId>model</artifactId>
        <version>0.001-SNAPSHOT</version>
    </parent>

    <artifactId>nato-model</artifactId>
    <packaging>jar</packaging>
    <name>nato-model</name>

    <dependencies>
        <dependency>
            <groupId>com.eros</groupId>
            <artifactId>core-model</artifactId>
            <version>${main.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.1</version>
                <configuration>
                    <verbose>false</verbose>
                    <removeOldOutput>false</removeOldOutput>
                    <markGenerated>true</markGenerated>
                </configuration>

                <executions>

                    <execution>
                        <id>b</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <generatePackage>com.eros.model.nato.n5k</generatePackage>
                            <generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
                            <schemaDirectory>
                                ${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds
                            </schemaDirectory>
                            <schemaIncludes>
                                <include>n5k.xsd</include>
                            </schemaIncludes>
                            <bindingDirectory>${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds</bindingDirectory>
                            <bindingIncludes>
                                <include>n5k.xjb</include>
                            </bindingIncludes>
                            <strict>false</strict>
                            <forceRegenerate>true</forceRegenerate>
                        </configuration>
                    </execution>
                    <execution>
                    <id>n7k</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generatePackage>com.eros.model.nato.n7k</generatePackage>
                        <generateDirectory>${project.build.directory}/generated-sources/jaxb</generateDirectory>
                        <schemaDirectory>
                            ${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds
                        </schemaDirectory>
                        <schemaIncludes>
                            <include>n7k.xsd</include>
                        </schemaIncludes>
                        <bindingDirectory>${project.basedir}/../../schema/src/main/xsd/com/eros/model/nato/custom_xsds</bindingDirectory>
                        <strict>false</strict>
                        <forceRegenerate>true</forceRegenerate>
                    </configuration>
                </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

</project>

我的n5k.xjb文件如下所示: -

<?xml version="1.0" ?>
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" schemaLocation="./n5k.xsd">
        <jaxb:bindings>
            <jaxb:globalBindings typesafeEnumMaxMembers="1024"/>
        </jaxb:bindings>
</jaxb:bindings>

我的n7k.xjb如下所示: -

<?xml version="1.0" ?>
<jaxb:bindings version="1.0" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" schemaLocation="n7k.xsd">
        <jaxb:bindings>
            <jaxb:globalBindings typesafeEnumMaxMembers="1024"/>
        </jaxb:bindings>
</jaxb:bindings>

但是在编译时我收到以下错误: -

Error while parsing schema(s).Location [ file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n5k.xjb{2,102}].
com.sun.istack.SAXParseException2; systemId: file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n5k.xjb; lineNumber: 2; columnNumber: 102; "file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n5k.xsd" is not a part of this compilation. Is this a mistake for "file:/Users/tuk/code/github/eros/main/schema/src/main/xsd/com/eros/model/nato/custom_xsds/n7k.xsd"

有人能让我知道我做错了吗?

环境: -

  • Java 8
  • Maven 3.5

1 个答案:

答案 0 :(得分:0)

我认为问题来自n7k.xsd的汇编。在第二次执行中,您未配置bindingIncludes。显然,使用了n7k.xjbn5k.xjb。并且n5k.xjb引用n5k.xsd,这不是此编译的一部分。

要解决此问题,请尝试添加:

<bindingIncludes>
    <include>n7k.xjb</include>
</bindingIncludes>

到第二次执行的配置。