如何构建具有不同依赖项的 war 的多个版本
How to build several versions of a war with different dependencies
我面临这样一种情况,我需要使用不同的依赖集构建不同的 war,以便在 Tomcat 7 和 WebSphere 8 下都可以部署(WebSphere 提供了大量的依赖项它自己的),我正在寻找最好的方法。
- 使用配置文件:是个坏主意,因为我无法将 maven-release 告诉 运行 两次,一次使用 tomcat 配置文件,一次使用 websphere。
- 使用 maven-war 插件的不同执行:效果更好,但我必须使用 "packagingExcludes" 配置手动排除每个不需要的 jar(我不能告诉 maven 使用特定的配置文件或每次执行的依赖项),使该配置非常脆弱
- 使用 war 覆盖:也许是个好主意,但我不喜欢 Maven 忽略原始 war 中声明的每个依赖项这一事实(因此我们可以有多个相同的版本第二个工件 war 如果我们不小心,配置会非常脆弱)
- 使用汇编:似乎比war覆盖好一点,仍然需要大量手动配置
- 使用不同的模块:我不能在另一个 war 中重用 class 中声明的,我们的 WebSphere 中有一个错误阻止我们声明所有 classes 在依赖项目中(如果使用它的 class 在 WEB-INF/lib 中的 jar 中,则找不到 JAX-RS 注释,它仅当它作为 class 文件部署时才有效WEB-INF/classes)
您在实际项目中如何处理此类情况?我错过了什么?
汇编完成工作:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>websphere8</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>war</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/${project.build.finalName}</directory>
<outputDirectory></outputDirectory>
<excludes>
<exclude>WEB-INF/lib/*.jar</exclude>
</excludes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>WEB-INF/lib</outputDirectory>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>javax.ws.rs:jsr311-api:*</exclude>
<exclude>org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:*</exclude>
<exclude>xml-apis:xml-apis:*</exclude>
<exclude>xerces:xercesImpl:*</exclude>
<exclude>org.hibernate.javax.persistence:hibernate-jpa-2.0-api:*</exclude>
<exclude>org.ow2.jotm:jotm-core:*</exclude>
<exclude>org.glassfish.hk2.external:javax.inject:*</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>
我面临这样一种情况,我需要使用不同的依赖集构建不同的 war,以便在 Tomcat 7 和 WebSphere 8 下都可以部署(WebSphere 提供了大量的依赖项它自己的),我正在寻找最好的方法。
- 使用配置文件:是个坏主意,因为我无法将 maven-release 告诉 运行 两次,一次使用 tomcat 配置文件,一次使用 websphere。
- 使用 maven-war 插件的不同执行:效果更好,但我必须使用 "packagingExcludes" 配置手动排除每个不需要的 jar(我不能告诉 maven 使用特定的配置文件或每次执行的依赖项),使该配置非常脆弱
- 使用 war 覆盖:也许是个好主意,但我不喜欢 Maven 忽略原始 war 中声明的每个依赖项这一事实(因此我们可以有多个相同的版本第二个工件 war 如果我们不小心,配置会非常脆弱)
- 使用汇编:似乎比war覆盖好一点,仍然需要大量手动配置
- 使用不同的模块:我不能在另一个 war 中重用 class 中声明的,我们的 WebSphere 中有一个错误阻止我们声明所有 classes 在依赖项目中(如果使用它的 class 在 WEB-INF/lib 中的 jar 中,则找不到 JAX-RS 注释,它仅当它作为 class 文件部署时才有效WEB-INF/classes)
您在实际项目中如何处理此类情况?我错过了什么?
汇编完成工作:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>websphere8</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>war</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/${project.build.finalName}</directory>
<outputDirectory></outputDirectory>
<excludes>
<exclude>WEB-INF/lib/*.jar</exclude>
</excludes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>WEB-INF/lib</outputDirectory>
<useTransitiveFiltering>true</useTransitiveFiltering>
<excludes>
<exclude>javax.ws.rs:jsr311-api:*</exclude>
<exclude>org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:*</exclude>
<exclude>xml-apis:xml-apis:*</exclude>
<exclude>xerces:xercesImpl:*</exclude>
<exclude>org.hibernate.javax.persistence:hibernate-jpa-2.0-api:*</exclude>
<exclude>org.ow2.jotm:jotm-core:*</exclude>
<exclude>org.glassfish.hk2.external:javax.inject:*</exclude>
</excludes>
</dependencySet>
</dependencySets>
</assembly>