2009-10-05 71 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