我正在使用maven货物插件下载tomcat作为我的构建的一部分,并把我的战争放在正确的地方。 然后,我使用maven程序集将其压缩并将其全部提取到服务器上。如何使用Maven-Cargo替换Tomcat端口?
现在我想用xmlReplacements更改tomcat conf/server.xml中的端口号。
这是我在做什么的例子,但如果你运行它,你会看到,在目标目录在server.xml还称8080
是我保持服务器的修改后的副本的唯一选择.xml在项目中,并用它替换整个文件?或者我没有正确使用此功能?还是它坏了?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>question</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<tomcat.version>8.0.24</tomcat.version>
</properties>
<build>
<plugins>
<!--Create a war-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<!--This is an empty demo project-->
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!--Create the Tomcat bundle with our war in it-->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.15</version>
<configuration>
<container>
<!--containerId must be equal to one of the containers supported by Cargo -->
<!--https://codehaus-cargo.github.io/cargo/Container.html-->
<containerId>tomcat8x</containerId>
<artifactInstaller>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat</artifactId>
<version>${tomcat.version}</version>
</artifactInstaller>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/cargo/installs/tomcat-${tomcat.version}/apache-tomcat-${tomcat.version}
</home>
<!--Allegedly change the port number-->
<xmlReplacements>
<xmlReplacement>
<file>conf/server.xml</file>
<xpathExpression>/Server/Service/Connector[1]</xpathExpression>
<attributeName>port</attributeName>
<value>9090</value>
</xmlReplacement>
</xmlReplacements>
</configuration>
<deployables>
<deployable>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<type>war</type>
</deployable>
</deployables>
</configuration>
<executions>
<execution>
<id>cargo-deploy</id>
<phase>package</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>