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

标签 maven tomcat maven-cargo

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

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

这是我正在做的一个例子,但如果你运行它,你会看到目标目录中的 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>

最佳答案

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

关于maven - 如何使用Maven-Cargo替换Tomcat端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32262253/

相关文章:

eclipse - 在 Eclipse 中作为 maven 安装运行时如何更改 jar 输出目录?

java - 我应该在spark应用程序中包含hadoop-common还是hadoop-core

java - tomcat-maven-plugin 具有多个模块,仅构建一场 war

spring - 使用重写规则将 http 重定向到 https 时,AlwaysOn 功能无法正常工作

tomcat - Icefaces 打开 jsf 和 icefaces jar 文件数百次

java - Spring 应用程序在 Tomcat 上部署失败 : whats wrong with applicationContext?

maven - 将 Maven Cargo artifactInstaller 用于 GlassFish 3.x

java.lang.NoClassDefFoundError - org/apache/spark/sql/hive/HiveContext

java - 未能停止 Tomcat 中的 Elasticsearch 线程

tomcat - 代码之家 : difference between existing and installed configuration?