如何使用Maven Cargo替换Tomcat端口?

如何使用Maven Cargo替换Tomcat端口?,maven,tomcat,maven-cargo,Maven,Tomcat,Maven Cargo,我正在使用maven cargo插件下载tomcat作为构建的一部分,并将我的war放在正确的位置。 然后,我使用maven assembly将其压缩并在服务器上解压缩 现在我想使用更改tomcat conf/server.xml中的端口号 这是我正在做的一个示例,但是如果您运行它,您将看到targetdir中的server.xml仍然显示8080 我唯一的选择是在项目中保留server.xml的修改副本,并用它替换整个文件吗?还是我没有正确使用此功能?还是坏了 <?xml version

我正在使用maven cargo插件下载tomcat作为构建的一部分,并将我的war放在正确的位置。 然后,我使用maven assembly将其压缩并在服务器上解压缩

现在我想使用更改tomcat conf/server.xml中的端口号

这是我正在做的一个示例,但是如果您运行它,您将看到targetdir中的server.xml仍然显示8080

我唯一的选择是在项目中保留server.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>

4.0.0
com.stackoverflow
问题
1.0-快照
战争
8.0.24
org.apache.maven.plugins
maven战争插件
2.6
假的
org.codehaus.cargo
cargo-maven2-plugin
1.4.15
tomcat8x
org.apache.tomcat
雄猫
${tomcat.version}
独立的
${project.build.directory}/cargo/installs/tomcat-${tomcat.version}/apache-tomcat-${tomcat.version}
conf/server.xml
/服务器/服务/连接器[1]
港口
9090
${project.groupId}
${project.artifactId}
战争
货物调配
包裹
部署

我的问题是双重的。我有错误的家和错误的阶段。简而言之,我改为:

          <configuration>
            <type>standalone</type>
            <home>${project.build.directory}/apache-tomcat-${tomcat.version}</home>
            <!--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>


        </configuration>
        <executions>
          <execution>
            <id>cargo-deploy</id>
            <phase>package</phase>
            <goals>
              <goal>configure</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
然后我注意到示例中有一个tomcat base dir用于
home
。当我改变这一点(而不是指向货物安装)它终于工作了


但是,我应该注意到,在server.xml中,不同的不仅仅是端口。其他一些属性的格式和顺序也不同。

如果您想更改Tomcat上的端口,可以在配置属性中使用cargo.servlet.port属性,可以设置的所有可能属性的列表如下所示。 可以找到如何设置配置属性的示例

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.15:configure (cargo-deploy) on project question: Execution cargo-deploy of goal org.codehaus.cargo:cargo-maven2-plugin:1.4.15:configure failed: Failed to create a Tomcat 8.x standalone configuration: Invalid configuration dir [C:\Question\target/cargo/installs/tomcat-8.0.24/apache-tomcat-8.0.24]. When using standalone configurations, the configuration dir must point to an empty directory. Note that everything in that dir will get deleted by Cargo. -> [Help 1]
[ERROR]