2009-09-30 39 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