2013-08-05 91 views
0

當試圖創建一個maven版本時,我需要resouces soures jar,javadoc jar和編譯類jar,這很容易通過現有的插件實現。maven jar選項,在編譯時創建一個額外的jar

但是我確實有XSD的src/main/resources/xsd文件夾,我更喜歡在構建過程中在不同的jar中創建它,這有可能嗎?

感謝您的幫助提前

回答

0

您可以使用自定義插件或assembly將其他工件添加到您的Maven版本。程序集允許您將任何資源組定義爲新的製造品。這種新的人造物將成爲您現有人造物的「附屬品」,就像源罐一樣。

當創建你需要定義一個描述符,並把它放在像src/main/assembly/xsd.xml

描述符看起來像一個組件:

<assembly> 
    <id>xsd</id> 
    <formats> 
     <format>zip</format> 
    </formats> 
    <fileSets> 
     <fileSet> 
      <directory>src/main/resources/xsd</directory> 
      <includes> 
       <include>*.xsd</include> 
      </includes> 
     </fileSet> 
    </fileSets> 
</assembly> 

第二部分是組件插件配置,將看例如:

<build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.4</version> 
     <configuration> 
      <descriptors> 
      <descriptor>src/main/assembly/xsd.xml</descriptor> 
      </descriptors>   
     </configuration> 
     <executions> 
       <execution> 
       <id>make-xsd-zip</id> <!-- this is used for inheritance merges --> 
       <phase>package</phase> <!-- bind to the packaging phase --> 
       <goals> 
       <goal>single</goal> 
       </goals> 
      </execution> 
     </executions> 
     </plugin> 
    </plugins> 
    </build> 

此配置應該給你的名字爲:<artifactid>-<version>-<assemblyid>.zip

0

好,MAVEN本身不支持從單一pom.xml多個工件。但是你可以創建另一個空項目只有一個pom創建另一個罐子

codebase 
    |- pom.xml 
    |- src 
    |- xsdJar 
     |- pom.xml 
    |- [other stuff] 

現在,在xsdJar\pom.xml

<project> 
    ... 
    <build> 
    <plugins> 
     ... 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>2.4</version> 
     <configuration> 
      <includes> 
      <include>../src/main/resources/xsd/*</include> 
      </includes> 
     </configuration> 
     </plugin> 
     ... 
    </plugins> 
    </build> 
    ... 
</project> 

此外,調用上述模塊在主pom.xml

<modules> 
    <module>xsdJar</module> 
</modules> 
相關問題