首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Maven-Cargo替换Tomcat端口?

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

Stack Overflow用户
提问于 2015-08-28 02:04:55
回答 2查看 3K关注 0票数 1

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

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

这是我正在做的事情的一个例子,但是如果您运行它,您将看到目标dir中的server.xml仍然是8080。

我唯一的选择是在项目中保留一个修改过的server.xml副本并用它替换整个文件吗?还是我没有正确地使用这个功能?还是坏了?

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-08-28 02:56:11

我的问题是两方面的。我有错误的家和错误的阶段。简单地说,我改变了这一观点:

代码语言:javascript
复制
          <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>

细节:我克隆了源代码来查看样本,然后播放点的区别。

当我将执行绑定从deploy阶段更改为configure阶段时,它的抱怨如下:

代码语言:javascript
复制
[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]

然后我注意到样本中有一个home的猫基dir。当我改变这个(而不是指向货物安装)时,它终于起作用了!

但是,我应该注意到,server.xml中的端口比端口更不一样。其他一些属性的格式设置和排序也不同。

票数 0
EN

Stack Overflow用户

发布于 2016-02-06 08:38:16

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32262253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档