我有一个pom.xml文件和一个单独的assembly-descriptor.xml文件。最终结果是一个tar.gz文件,其中包含我的Tomcat Web应用程序和一些jar文件。当我在我的本地开发机(Mac OS 10.7和Maven 3.0.3)上构建时,生成的tar.gz包含有效的jar文件。当构建在我们的构建盒子上运行(Jenkins on linux server/Maven 3.0.3),并部署到生产服务器时,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文件:
这里是装配描述符(assembly-descriptor.xml):
最后,本地构建和生产构建之间的另一个区别是生产构建使用本地存储库,而我的本地构建则没有。我没有过多关注这一点,因为我能够在本地(即无本地存储库问题)重新生成JAR文件并发现重复/损坏问题。
以下是我的pom.xml文件:
<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>...
这里是装配描述符(assembly-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文件并发现重复/损坏问题。