这对 Maven 来说非常棘手。您可以在 maven 生命周期的 package 阶段尝试多次执行 maven-[jar/war/ear]-plugins。在每次执行中,您可以设置不同的分类器。
此外,在执行 maven-war-plugin 时,您可以使用 an<overlay>
将具有正确分类器的扩展名放入 WAR 文件中。在 maven-ear-plugin 的执行中,您可以将具有正确分类器的 WAR 文件指定为<webModule>
.
例子
在扩展模块中,您可以像这样配置 maven-jar-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>extension-AA</id>
<phase>package</phase>
<goals>jar</goals>
<configuration>
<classifier>AA</classifier>
</configuration>
</execution>
<execution>
<id>extension-BB</id>
<phase>package</phase>
<goals>jar</goals>
<configuration>
<classifier>BB</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
WAR 模块的配置非常相似:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>extension-AA</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<overlays>
<overlay>
<groupId>com.example</groupId>
<artifactId>extension-1</artifactId>
<classifier>AA</classifier>
</overlay>
</overlays>
</configuration>
</execution>
<execution>
<id>extension-BB</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<overlays>
<overlay>
<groupId>com.example</groupId>
<artifactId>extension-1</artifactId>
<classifier>BB</classifier>
</overlay>
</overlays>
</configuration>
</execution>
</executions>
</plugin>
最后是EAR模块的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<executions>
<execution>
<id>extension-AA</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<classifier>AA</classifier>
<modules>
<webModule>
<groupId>com.example</groupId>
<artifactId>war-1</artifactId>
<classifier>AA</classifier>
</webModule>
</modules>
</configuration>
</execution>
<execution>
<id>extension-BB</id>
<phase>package</phase>
<goals>
<goal>ear</goal>
</goals>
<configuration>
<classifier>BB</classifier>
<modules>
<webModule>
<groupId>com.example</groupId>
<artifactId>war-1</artifactId>
<classifier>BB</classifier>
</webModule>
</modules>
</configuration>
</execution>
</executions>
</plugin>