2009-09-30 38 views
20

到Maven的专家那里: 我试图将非Java项目工件(.NET)打包到一个zip文件中。我有2个问题:Maven创建平坦的zip组件

如果我改变包装在我的POM拉上<packaging>zip</packaging>,我得到这个错误信息:[INFO] Cannot find lifecycle mapping for packaging: 'zip'. Component descriptor cannot be found in the component repository: org.apache.mav en.lifecycle.mapping.LifecycleMappingzip. OK,没什么大不了的 - 我把它改成<packaging>pom</packaging>摆脱以其它方式产生无用的罐子在目标目录中

我的主要问题是我打包到ZIP中的文件嵌套在几个目录中,但我需要将它们放到ZIP的顶层目录中。这是我的汇编文件:

<assembly> 
    <id>bin</id> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>${basedir}/${project.artifactId}</directory> 
     <includes> 
     <include>**/Bin/Release/*.dll</include> 
     <include>**/Bin/Release/*.pdb</include> 
     </includes> 
    </fileSet> 
    </fileSets> 
</assembly> 

当我运行这一点 - 我会得到ZIP文件,但文件将开始使用C嵌套:\后跟完整路径。为了让你的想法 - 项目转储它的二进制文件到以下结构 ProjectFoo\ProjectFoo\subproject1\Bin\Release\foo.dll,我需要ZIP\foo.dll

这里的组件插件配置:

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<configuration> 
    <descriptors> 
     <descriptor>assembly.xml</descriptor> 
    </descriptors> 
</configuration> 
<executions> 
    <execution> 
     <id>zip</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
    </execution> 
</executions> 

也许我只需要使用antrun和执行蚂蚁拉链任务?

回答

27

正如您所见,没有拉链包装类型,因此您可以选择使用pom包装。

您在程序集插件的处理中遇到了一些问题。你可以通过在程序集中指定多个文件集来解决这个问题,<outputDirectory>/<outputDirectory>,一个用于你想包含的每个目录,这显然是一个PITA,可能不是一个可接受的解决方案。

另一种方法是使用Ant副本任务将所有DLL复制到暂存目录中,然后将该目录包含在程序集中。

下面的配置应该做你以后:

的antrun-插件配置:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.3</version> 
    <executions> 
     <execution> 
     <phase>process-resources</phase> 
     <configuration> 
      <tasks> 
      <copy todir="${project.build.directory}/dll-staging"> 
       <fileset dir="${basedir}/${project.artifactId}"> 
       <include name="**/Bin/Release/*.dll"/> 
       <include name="**/Bin/Release/*.pdb"/> 
       </fileset> 
       <flattenmapper/> 
      </copy> 
      </tasks> 
     </configuration> 
     <goals> 
      <goal>run</goal> 
     </goals> 
     </execution> 
    </executions> 
    </plugin> 

大会:

<assembly> 
    <id>bin</id> 
    <formats> 
    <format>zip</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>${project.build.directory}/dll-staging</directory> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <include>*.dll</include> 
     <include>*.pdb</include> 
     </includes> 
    </fileSet> 
    </fileSets> 
</assembly> 
+0

正是我需要的!谢谢Rich! – Bostone 2009-09-30 23:44:53

+0

不用客气 – 2009-10-01 08:25:35

+0

尽管如此,还是有一个问题。该zip仍然维护一个类型为“artifactId-Version”的顶级目录。当我提取zip文件时,所有的文件都不在'/'中,而是在'/ Foo-1.0-SNAPSHOT /'中。然而,这些文件被正确地复制到目标/ dll-staging – Bostone 2009-10-01 21:01:48