2014-09-11 55 views
1

我試圖使用Assembly插件包括依賴條件以及Maven的組裝插件,包括廣口瓶的依賴和外部文件

這裏是我的組裝插件

<plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <version>2.4.1</version> 
       <executions> 
        <execution> 
         <id>create-executable-jar</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 

        </execution> 
       </executions> 

       <configuration> 
          <descriptorRefs> 
           <descriptorRef> 
            jar-with-dependencies 
           </descriptorRef> 
            </descriptorRefs> 
            <descriptors> 
             <descriptor>src/assembly/assembly.xml</descriptor> 
            </descriptors> 
          <archive> 
           <manifest> 
            <mainClass>com.sarm.myproject.XMLParser.LPUnMarshaller</mainClass> 
           </manifest> 
          </archive> 
         </configuration> 

      </plugin> 

這裏是我的assembly.xml描述符,我使id與descritpor ref相同,因爲它爲這個描述符創建了一個不同的jar。所以我有兩個描述符,一個是jar-with-dependencies描述符ref,另一個是下面的描述符,在這種情況下發生的是它創建兩個jar,第二個jar覆蓋前一個jar。如何將這兩個包含在同一個罐子裏?

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> 
    <id>jar-with-dependencies</id> 
    <formats> 
    <format>jar</format> 
    </formats> 


    <fileSets> 
    <fileSet> 
     <directory>${basedir}</directory> 
     <includes> 
     <include>*.xml</include> 
     </includes> 

    <excludes> 
     <exclude>30000dests.xml</exclude> 

     </excludes> 

    </fileSet> 
    <fileSet> 
     <directory>${basedir}/test</directory> 
     <includes> 
     <include>*.xml</include> 
     </includes> 

    </fileSet> 
    </fileSets> 
</assembly> 

編輯:我已經嘗試了一些其他辦法,我已經看到,如果我用assembly.xml作爲一個描述符,一個新的jar沿側創建創建以及任何其他默認罐子。所以我最終得到兩個罐子。默認的jar是一個像jar插件配置的可執行文件。即使程序集插件被配置爲使用我的主類名稱來創建manifest.mf,但通過assmbly.xml創建的jar不可執行,並且其中包含可執行jar的我的項目名稱的文件夾。

我使用mvn clean install來構建我的項目和jar文件。

回答

0

您應該創建兩個產生兩個罐子的模塊。通常,Maven將爲每個模塊生成一個jar文件,並將模塊名稱作爲jar名稱。 Maven建議每個模塊都有一個輸出工件。

如果您擔心重複代碼。你可以通過擁有一個父pom來繼承相關的東西。

+0

感謝您的回覆。這個想法是隻有一個罐子。依賴和外部文件。兩個罐子,一個有libs,一個只有外部,第二個沒有上課,他們不會真的幫助我很多。我只會運行jar。此外,罐子以爆炸形式出現。如果我用依賴集合使用assembly.xml那麼我可以有罐子,但是我錯過了代碼。爲什麼編譯後的類不能與使用assembly.xml創建的jar打包在一起。我非常喜歡使用assembly.xml的想法,它非常靈活。 – sarmahdi 2014-09-12 14:34:09