maven-jaxb2-plugin:即使 xsd 和 xjb 文件位于同一位置,解析模式位置也会出错
maven-jaxb2-plugin: Error in parsing schema location even when xsd and xjb files are in same location
我有一个 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
- 行家 3.5
我认为问题出在n7k.xsd
的编译上。在第二次执行中,您没有配置 bindingIncludes
。所以显然 n7k.xjb
和 n5k.xjb
都被使用了。并且 n5k.xjb
引用了 n5k.xsd
,它不是本汇编的一部分。
要解决,请尝试添加:
<bindingIncludes>
<include>n7k.xjb</include>
</bindingIncludes>
到第二次执行的配置
我有一个 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
- 行家 3.5
我认为问题出在n7k.xsd
的编译上。在第二次执行中,您没有配置 bindingIncludes
。所以显然 n7k.xjb
和 n5k.xjb
都被使用了。并且 n5k.xjb
引用了 n5k.xsd
,它不是本汇编的一部分。
要解决,请尝试添加:
<bindingIncludes>
<include>n7k.xjb</include>
</bindingIncludes>
到第二次执行的配置