2014-04-02 36 views
0

我創建了一個簡單的Maven項目,它使用Jaxb將模式編譯爲Java文件。一切似乎都在工作,但問題是生成的包名是倒退:Maven Jaxb生成的軟件包名稱是向後的

Windows Explorer

我的XML架構如下所示:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://com.mystuff.jaxb.inventorycontrol.inventorydata" 
    targetNamespace="http://com.mystuff.jaxb.inventorycontrol.inventorydata" elementFormDefault="qualified" version="1.0.0"> 
    .... 
    ....  
    <xs:complexType name="InventoryItemListType"> 
     <xs:sequence> 
      <xs:element name="Item" type="InventoryItemType" /> 
     </xs:sequence> 
    </xs:complexType>   
</xs:schema> 

命名空間http://com.mystuff.jaxb.inventorycontrol.inventorydata開始與COM和結束與盤點數據,所以我認爲這將是包/文件夾順序:

com\mystuff\jaxb\inventorycontrol\inventorydata 

,但礦向後結束:

inventorydata\inventorycontrol\jaxb\mystuff\com\ 

不知道,如果是矯枉過正粘貼一些我的pom.xml的在這裏,但我想這不會傷害。

這裏是我的根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"> 
    .... 
    <packaging>pom</packaging> 
    <groupId>com.mystuff.jaxb</groupId> 
    <artifactId>inventorycontrol</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    .... 
    <build> 
     <pluginManagement> 
      <plugins> 
       .... 
       <plugin> 
        <groupId>org.jvnet.jaxb2.maven2</groupId> 
        <artifactId>maven-jaxb2-plugin</artifactId> 
        <version>${maven-jaxb2-plugin-version}</version> 
        <configuration> 
         <catalog>src/main/resources/catalog.xml</catalog> 
         <catalogResolver>org.jvnet.jaxb2.maven2.resolver.tools.ClasspathCatalogResolver</catalogResolver> 
         <extension>true</extension> 
         <schemaDirectory>${basedir}/src/main/resources/xsd</schemaDirectory> 
         <schemaIncludes> 
          <include>*.xsd</include> 
         </schemaIncludes> 
        </configuration> 
        <executions> 
         <execution> 
          <goals> 
           <goal>generate</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </pluginManagement>  
    </build> 

    <modules> 
     <module>inventorydata</module> 
    </modules> 

</project> 

這裏是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"> 
    .... 
    <packaging>pom</packaging> 
    <parent> 
     <groupId>com.mystuff.jaxb</groupId> 
     <artifactId>inventorycontrol</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <groupId>com.mystuff.jaxb.inventorycontrol</groupId> 
    <artifactId>inventorydata</artifactId> 
    .... 
    <build> 
     <plugins> 
      .... 
      <plugin> 
       <groupId>org.jvnet.jaxb2.maven2</groupId> 
       <artifactId>maven-jaxb2-plugin</artifactId> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

_UPDATE_

當我建立了我的項目,我基本上從舊項目複製/粘貼schema/pom文件到這個新項目。老項目的架構看起來像下面這樣:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.cmv.com/java/maven/jaxb/schemas/core/types" 
    targetNamespace="http://www.cmv.com/java/maven/jaxb/schemas/core/types" elementFormDefault="qualified" version="1.0.0"> 
    .... 
    <xs:complexType name="PoundsWeightType"> 
     <xs:sequence> 
      <xs:element name="Value" type="PositiveFloat" /> 
     </xs:sequence> 
     <xs:attribute name="Units" type="UnitsEnum" use="required" fixed="Lbs" /> 
    </xs:complexType> 
</xs:schema>  

而我的包生成該項目是:

com\cmv\java\maven\jaxb\schemas\core\types 

Project With Correct Order

這是我期望的那樣。

回答

2

Java組件,軟件包等使用反向dns命名。您正在使用DNS格式指定命名空間,也就是說,您打算將其撤銷。

命名空間com.mystuff.jaxb.inventorycontrol.inventorydata,寫出來的網址是:http://inventorydata.inventorycontrol.jaxb.mystuff.com

+0

我有我從複製的POM信息的另一個Maven項目並使用相同的排序爲命名空間和包名結束了,我會期待,先用com吧。當我複製/修改新的pom文件時,我確信我沒有錯過任何東西,所以我不知道爲什麼這種行爲是不同的。 –

+0

您的poms看起來不錯 - 您在xml架構中使用DNS格式。 – blueberryfields

+0

你是否暗示我的架構中的命名空間是http://inventorydata.inventorycontrol.jaxb.mystuff.com?如果是這樣,那從我看到的所有模式中有99%倒退。而且,正如我上面所說的,我在其他項目中使用了相同的順序,並且都很好。 –