2009-10-05 66 views
7

在我的項目中,我創建了很多程序集(4-5),並將它們輸出到target.1/2這些程序集沒有取得它們的最終名稱(或程序集ID),但按照格式artifactID-version.jar ..這很混亂 這是爲什麼呢?創建程序集的問題

從我的pom.xml提取物 -

<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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.apple</groupId> 
    <artifactId>maven</artifactId> 
    <name>maven_XX</name> 
    <version>0.0.1-SNAPSHOT</version> 


    <build> 
    <plugins> 
    <!-- Added to avoid the compilation issue wrt Annotations --> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <configuration> 
      <source>1.5</source> 
      <target>1.5</target> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.4.2</version> 
     <configuration> 
      <skip>true</skip> 
     </configuration> 
     </plugin> 
     <plugin> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.2-beta-4</version> 
     <executions>    
      <execution> 
      <id>clientjar</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <configuration> 
       <finalName>XX_client</finalName> 
       <appendAssemblyId>false</appendAssemblyId> 
       <descriptors> 
       <descriptor> 
        ${basedir}/src/main/resources/assemblies/clientjar.xml 
       </descriptor> 
       </descriptors> 
      </configuration> 
      </execution> 
      <execution> 
      <id>11***</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <configuration> 
       <finalName>11server</finalName> 
       <appendAssemblyId>false</appendAssemblyId> 
       <descriptors> 
       <descriptor> 
        ${basedir}/src/main/resources/assemblies/11server.xml 
       </descriptor> 
       </descriptors> 
       <outputDirectory>assemblies-target</outputDirectory> 
      </configuration> 
      </execution> 
      <execution> 
      <id>cache</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
      <configuration> 
       <finalName>cache</finalName> 
       <appendAssemblyId>false</appendAssemblyId> 
       <descriptors> 
       <descriptor> 
       ${basedir}/src/main/resources/assemblies/cache.xml 
       </descriptor> 
       </descriptors> 
       <outputDirectory>assemblies-target</outputDirectory> 
      </configuration> 
      </execution> 
+0

它不是random.specific程序集不是以下。 每個預期的輸出是提供最終名稱的jar。 但我把他們作爲 - 項目名稱version.jar – user170114 2009-10-05 11:13:55

回答

8

當您運行的組件,你看到這樣的事情輸出到控制檯通過Maven的?:

[INFO] [assembly:single {execution: 11***}] 
[INFO] Reading assembly descriptor: C:\test\test-parent2/src/main/resources/assemblies/11server.xml 
[INFO] Building jar: C:\test\test-parent2\assemblies-target\11server.jar 
[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing. 
Instead of attaching the assembly file: C:\test\test-parent2\assemblies-target\11server.jar, it will become the file for 
main project artifact. 
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-de 
terministic! 

這是因爲所有你的程序集指定<appendAssemblyId>false</appendAssemblyId>並且沒有指定分類器。該分類器在2.2-beta-4版本中已被棄用,因此無論如何都被忽略,這是該插件中的一個錯誤/功能。
因此,Maven將始終使其中一個程序集成爲jar包裝的「主要」工件,而您在目標程序集目錄中看不到它。

要解決此問題,您可以指定您的項目已打包pom,然後將jar生命週期的目標綁定到pom。

要啓用process-resourcescompile目標,您可以將包裝更改爲pom,將以下配置添加到您的pom中,並運行標準生命週期目標。例如mvn packagemvn install

<plugin> 
    <artifactId>maven-resources-plugin</artifactId> 
    <executions>    
    <execution> 
     <id>process-resources</id> 
     <phase>process-resources</phase> 
     <goals> 
     <goal>resources</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 
<plugin> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <executions>    
    <execution> 
     <id>compile</id> 
     <phase>compile</phase> 
     <goals> 
     <goal>compile</goal> 
     </goals> 
    </execution> 
    </executions> 
</plugin> 

的必然罐子生命週期目標的完整列表可在建於Introduction to the Build Lifecycle的生命週期綁定部分找到。它們都遵循與process-resourcescompile目標類似的模式。在你的情況下,你可能想要省略jar的目標。

+0

嗨 當運行程序集,我得到警告,因爲你已經給。 所以,你的意思是說,我不喜歡使用目標=編譯的程序集(它給罐子),並啓用maven編譯目標? – user170114 2009-10-06 08:49:21

+0

不,我的意思是讓項目的包裝「pom」並配置插件,以便通常在jar生命週期中執行的目標在pom的生命週期中執行,資源和編譯插件上面的配置將在默認生命週期內執行,所以你仍然運行'mvn install'。這繞過了程序集插件 – 2009-10-06 09:05:46

+0

中的錯誤。 我將包裝更改爲「pom」。添加了您提供的兩個插件,並且未對配件進行任何配置更改。在運行mvn install時,大會,它給 - 引起:org.apache.maven.project.DuplicateArtifactAttachmentException:檢測到重複的工件附件。 – user170114 2009-10-06 09:56:18

11

Lyle的評論拉出到問題級別以提供可見性。

雖然以前的答案工程Lyle指出:

如果我理解正確的這個,好像什麼相當於在裝配插件中的錯誤有點侵入性的解決方法。相反,嘗試在配置中設置爲false。請參閱:MASSEMBLY-352

對於未附加到存儲庫分配的工件,這是一個很好的解決方案,對我而言效果很好。

... 
<appendAssemblyId>false</appendAssemblyId> 
<attach>false</attach> 
... 
+2

適用於「單一裝配」項目。 – 2014-06-20 11:27:21