我正在尝试使用 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将应用程序部署到生产或开发的所有服务器。
是否有可能通过处决或其他方式来实现?