我正在尝试构建一个skinny war,以便稍后包含在一个大型ear文件中。ear构建完全独立于我的war项目,并期望我提供一个带有正确清单文件的瘦war, ear承诺在其根/libs文件夹中提供提供的jar。
我面临的问题是获得战争清单。指定提供的jar文件在ear的/lib文件夹中,而编译/运行时jar文件在war中。也就是舱单。Mf类路径条目看起来像这样:
Class-Path: libs/commons-lang.jar commons-codec.jar
commons-lang的作用域是提供的,并且应该在ear的lib目录中。
common -codec是编译时的,预计将成为战争的一部分。
我已经探索了maven-war-plugin,但不知道如何让它提供classpathPrefix仅用于提供的依赖项。
建议好吗?
最终采用的解决方案(感谢所有的技巧和链接)要求ear提供的依赖项的作用域为提供,注意到这个hack: pseudo -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插件将这个新的skinny war部署到存储库:
<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>
@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>