在做的时候,mvn install我想在目标目录中得到2个WAR文件.一个将包含生产 web.xml,另一个将包含test/uat web.xml.
我试过这个:
<build>
<finalName>cas-server</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<webXml>src/main/config/prod/web.xml</webXml>
<warName>cas-prod</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<webXml>src/main/config/test/web.xml</webXml>
<warName>cas-test</warName>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但我最终只得到测试WAR.
Pas*_*ent 16
我不认为你可以一步到位(事实上,我很惊讶Maven没有抱怨你的设置,并想知道哪一个被应用)我建议使用配置文件,也许过滤来管理这个用途案件.
如果你web.xml真的不一样,你可以把你的maven-war-plugin配置放在两个配置文件中.或者,更好的是,你可以将它们合并成这样的东西:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<webXml>src/main/config/${env}/web.xml</webXml>
<warName>cas-test</warName>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
并env在两个配置文件中设置属性以web.xml在构建时选择正确的属性.
<profiles>
<profile>
<id>uat</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
如果您web.xml的相似(即,只有值不同),您可以在两个配置文件中定义属性及其值,并使用过滤来应用它们.像这样的东西:
<profiles>
<profile>
<id>env-uat</id>
<activation>
<property>
<name>env</name>
<value>uat</value>
</property>
</activation>
<properties>
<key1>uat_value_key_1</key1>
<keyN>uat_value_key_n</keyN>
</properties>
</profile>
<profile>
<id>env-prod</id>
<activation>
<property>
<name>env</name>
<value>prod</value>
</property>
</activation>
<properties>
<key1>prod_value_key_1</key1>
<keyN>prod_value_key_n</keyN>
</properties>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)
然后通过在命令行上传递env属性来激活一个配置文件或另一个配置文件,例如:
mvn -Denv=uat package
Run Code Online (Sandbox Code Playgroud)
另一种选择是将值放入特定的过滤器中,并在构建时选择正确的过滤器(如本文中所述).
有很多选择,但正如我所说,我不认为你可以做到这一点,如果没有runngin构建两次.
有关配置文件/过滤的更多资源
您可以告诉Maven Assembly插件只生成两个程序集.您只需为要创建的每个输出编写汇编描述符文件,并在插件配置中列出它们.
例如,我正在使用它来生成WAR文件和TGZ文件,但是没有理由不能以相同的方式执行两个WAR.然后mvn包将生成两个文件.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly-war.xml</descriptor>
<descriptor>src/main/assembly/assembly-dist.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>dist-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17076 次 |
| 最近记录: |