maven - 使用不同的配置运行多个 Maven 执行。maven 忽略配置的配置,除非以 id 为目标
问题描述
我正在尝试使用 tomcat7-maven-plugin 将我的 web 应用程序部署到运行 Tomcat 的多个服务器。
这是我的pom.xml
文件的一部分:
<profiles>
<profile>
<id>DevDeployment</id>
<activation>
<property>
<name>!production</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<executions>
<execution>
<id>localhost</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<url>http://127.0.01:8080/manager/text</url>
<server>TomcatServer</server>
<username>foo</username>
<password>boo</password>
</configuration>
</execution>
<execution>
<id>devserver</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<url>http://dev_server_ip:8080/manager/text</url>
<server>TomcatServer</server>
<username>foo</username>
<password>boo</password>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>ProductionDeployment</id>
<activation>
<property>
<name>production</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>production1</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<url>http://production1_ip:8080/manager/text</url>
<server>TomcatServer</server>
<username>foo</username>
<password>boo</password>
</configuration>
</execution>
<execution>
<id>production2</id>
<configuration>
<source>1.8</source>
<target>1.8</target>
<url>http://production2_ip:8080/manager/text</url>
<server>TomcatServer</server>
<username>foo</username>
<password>boo</password>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
我想要实现的是拥有两个不同的 Maven 配置文件,通过首先运行它将应用程序部署到 2 个开发服务器,并通过激活其他将应用程序部署到 2 个生产服务器。
所以当我运行命令时:
mvn tomcat7:redeploy -Dproduction
它进入生产服务器,当我运行时
mvn tomcat7:redeploy
它转到开发服务器。
我已经成功地制作了配置文件,并通过运行这些命令来选择正确的配置文件并运行它。
当我<executions>
用不同的<configuration>
标签定义多个时出现问题,maven 忽略这些配置并运行默认配置。
它仅在我直接按 Id 运行mvn tomcat7:redeploy@localhost
或mvn tomcat7:redeploy@devserver
定位执行时才有效。
所以很明显,目标是只需要运行 2 个命令:mvn tomcat7:redeploy -Dproduction
或者mvn tomcat7:redeploy
将应用程序部署到生产或开发的所有服务器。
是否有可能通过处决或其他方式来实现?
解决方案
推荐阅读
- docker - Confluent 平台和 java.nio.file.DirectoryNotEmptyException
- r - 将 Leaflet 的图标链接到 Shiny 中的情节线图
- java - 替换 org.hibernate.util.PropertiesHelper 的内容
- sublimetext3 - 在 sublime 中使用 cmd 键绑定 build_with
- angular - Mat-card-content 没有正确显示
- eigen - QCustomPlot 在图形中添加双精度需要很长时间
- java - Android 9 - KeyStore 异常 android.os.ServiceSpecificException
- c++ - 如何访问 QScxmlEcmaScriptDataModelPrivate 的成员?
- cryptography - 是否有用于匿名签名的集体签名的实现?
- c# - .net 核心最佳实践在哪里保存 JSON 模式文件