2017-06-12 73 views
0

我有一個pom.xml看起來象下面這樣: -Maven的JAXB2-插件:錯誤解析架構位置,即使XSD和XJB文件都在同一個位置

<?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

回答

0

我認爲問題來自於n7k.xsd編譯。在第二次執行中,您沒有配置bindingIncludes。所以顯然使用n7k.xjb以及n5k.xjb。並且n5k.xjb參考n5k.xsd這不是此彙編的一部分。

要解決,試着加入:

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

到第二執行的配置。