我正在尝试建立一个瘦小的战争,以便以后包含在一个大的耳朵文件中。 耳朵的构建完全独立于我的战争项目,并期望我提供一个瘦的战争,使用正确的清单文件,耳朵承诺在其root / libs文件夹中提供提供的jar。
我面临的问题是获得war的manifest.mf文件,以指定提供的jar在ear&#s; / libs文件夹中,并且编译/运行时jar文件处于战争状态。 即manifest.mf类路径条目想要如下所示:
Class-Path: libs/commons-lang.jar commons-codec.jar
commons-lang的范围是提供并预期在ear的libs目录中。
commons-codec是编译时间,预计会成为战争的一部分。
我已经探索过 maven-war-plugin ,但无法弄清楚如何让它供应 classpathPrefix 仅用于提供的依赖项。
建议吗?
最终采用的解决方案(感谢所有提示和链接) 需要将ear提供的依赖项作为提供的范围,并注意到hack:fake-application.xml:
<plugin>
<!--required to fix the war's manifest and skinny the war-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
<generateApplicationXml>true</generateApplicationXml>
<applicationXml>${project.basedir}/src/test/fake-ear/fake-application.xml</applicationXml>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals><goal>ear</goal></goals>
</execution>
</executions>
</plugin>
然后我将这个新的瘦小的战争部署到存储库,并使用maven deploy plugin:
<plugin>
<!--used in release build to deploy skinny war to nexus-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<executions>
<execution>
<id>deploy-file</id>
<phase>install</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<!--location of the skinny war after maven-ear-plugin builds it-->
<file>${project.build.directory}/${project.artifactId}-${project.version}/${artifactid}-${project.parent.version}.war</file>
<repositoryId>releases</repositoryId>
<url>${distributionManagement.repository.url}</url>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${artifactid}</artifactId>
<version>${project.parent.version}</version>
<packaging>war</packaging>
</configuration>
</execution>
</executions>
</plugin>
答案 0 :(得分:0)
@Tunaki的maven-ear-plugin
建议似乎总体上更好,但无论如何看看:https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html
您可以这样修改清单:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Class-Path>libs/commons-lang.jar commons-codec.jar</Class-Path>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>