2012-12-18 160 views
1

我有一個pom.xml文件和單獨的assembly-descriptor.xml文件。最終結果是一個tar.gz文件,其中包含我的tomcat webapp和一些jar文件。當我在我的本地開發框(Mac OS 10.7和Maven 3.0.3)上構建它時,生成的tar.gz包含一個有效的jar文件。當構建在我們的構建框(Linux服務器/ Maven 3.0.3上的Jenkins)上運行並被部署到生產服務器時,該jar文件幾乎是它應該的大小的兩倍並且已損壞。當我將Maven Assembly插件的版本更改爲2.3或2.4時,我可以在本地重現倍增/損壞問題。當我將它設置爲2.1或2.2或沒有版本(它默認爲2.2 beta 5)時,它在本地工作。但是不管我選擇什麼版本,在編譯框的tar gz步驟中構建失敗。 (本地Java版本= 1.6.0_37和構建系統是1.6.0_34,但我不認爲這種差異是難辭其咎)
這是我的pom.xml:tar gz文件在Maven build後包含損壞的jar文件

<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-assembly-plugin</artifactId> 
     <version>2.3</version> 
     <configuration> 
      <encoding>UTF-8</encoding> 
      <finalName>${project.build.finalName}_${project.version}</finalName> 
      <descriptors> 
       <descriptor>src/main/assembly/assembly-descriptor.xml</descriptor> 
      </descriptors> 
      <attach>true</attach> 
     <appendAssemblyId>false</appendAssemblyId> 
     </configuration> 
     <executions> 
      <execution> 
       <id>package-tar-gz</id> 
       <phase>package</phase> 
       <goals> 
        <goal>single</goal> 
       </goals> 
      </execution> 
     </executions> 
     </plugin>... 

` 這裏是組裝描述(組裝descriptor.xml):

<?xml version="1.0" encoding="UTF-8"?> 
    <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0  http://maven.apache.org/xsd/assembly-1.1.0.xsd"> 
    <id>bin</id> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <formats> 
    <format>tar.gz</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>${project.basedir}/src/main/tomcat</directory> 
     <filtered>true</filtered> 
     <excludes> 
      <exclude>**/*.war</exclude> 
     </excludes> 
     <outputDirectory>/</outputDirectory> 
    </fileSet> 
    </fileSets> 
</assembly> 

最後,本地構建和生產版本之間的另一個區別是,生產版本使用本地存儲庫和我的本地編譯沒有。我沒有給予這麼多的關注,因爲我能夠在本地複製jar文件加倍/損壞問題(即sans本地回購問題)。

+0

你能澄清一下**但不管我選擇什麼版本,構建焦油GZ時失敗**手段?你能顯示日誌輸出嗎? – khmarbaise

+0

對不起,這是誤導。所有版本的構建都是「成功」的。我的意思是,無論安裝什麼版本的插件,官方版本的jar文件都會被破壞。奇怪的是,我可以使用匯編插件版本2.3和2.4在我的本地版本上重新生成問題。我在這個網站上讀到另一篇文章,指出你可以指定在彙編打包期間不壓縮jar文件,但'compress'元素不被理解。 – user1814008

+0

解決方案:通過確保maven程序集插件版本(2.4)與程序集版本(1.1.2)對齊/兼容,解決了這個問題。另外,更重要的是,文件集定義很時髦。一旦我重寫並簡化了它,事情運行良好。特別是,有一個奇怪的定義是爲一個目錄過濾掉war文件,然後再過濾第二個包含war文件的定義。我認爲這個組合不是格式良好的,而是在一個平臺上工作,而不是另一個。 – user1814008

回答

0

嘗試刪除屬實,這可能是罪魁禍首