Maven Cargo Plugin 多次执行:用户名和密码是必填项

问题描述

我正在尝试使用 Cargo 插件部署到一个简单的 Tomcat 集群环境,有两个 Tomcat 节点:

  • tomcat1 (192.168.10.21)
  • tomcat2 (192.168.10.22)

尝试运行 mvn cargo:deploy 时出现以下错误

[ERROR] Failed to execute goal org.codehaus.cargo:cargo-maven3-plugin:1.9.4:deploy
 (default-cli) on project sample: Execution default-cli of goal 
org.codehaus.cargo:cargo-maven3-plugin:1.9.4:deploy Failed: The 
[cargo.remote.username] and [cargo.remote.password] properties are 
mandatory and need to be defined in your configuration. -> [Help 1]

我在两次执行中都指定了用户名和密码,但没有成功。我的 pom.xml 的 <build> 部分如下。有人可以帮忙吗?

编辑:提供整个 POM.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.0</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <groupId>org.jason</groupId>
  <artifactId>sample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>sample</name>
  <packaging>war</packaging>
  <description>Sample Project for Testing Cluster Setup</description>

  <properties>
    <java.version>11</java.version>
    <cargo.remote.username>jason</cargo.remote.username>
    <cargo.remote.password>password</cargo.remote.password>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-security</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>

<!--    <dependency>-->
<!--      <groupId>org.springframework.boot</groupId>-->
<!--      <artifactId>spring-boot-starter-test</artifactId>-->
<!--      <scope>test</scope>-->
<!--    </dependency>-->
<!--    <dependency>-->
<!--      <groupId>org.springframework.security</groupId>-->
<!--      <artifactId>spring-security-test</artifactId>-->
<!--      <scope>test</scope>-->
<!--    </dependency>-->
  </dependencies>

  <build>
      <finalName>sample</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven3-plugin</artifactId>
        <version>1.9.4</version>
        <configuration>
          <container>
            <containerId>tomcat9x</containerId>
            <type>remote</type>
          </container>
          <configuration>
            <type>runtime</type>
            <properties>
              <cargo.protocol>http</cargo.protocol>
              <cargo.servlet.port>8080</cargo.servlet.port>
            </properties>
          </configuration>
          <deployer>
            <type>remote</type>
          </deployer>
          <deployables>
            <deployable>
              <groupId>org.jason</groupId>
              <artifactId>sample</artifactId>
              <type>war</type>
            </deployable>
          </deployables>
        </configuration>
        <executions>
          <execution>
            <id>tomcat1</id>
            <configuration>
              <properties>
<!--                <cargo.remote.username>jason</cargo.remote.username>-->
<!--                <cargo.remote.password>password</cargo.remote.password>-->
                <cargo.hostname>192.168.10.21</cargo.hostname>
              </properties>
            </configuration>
          </execution>
          <execution>
            <id>tomcat2</id>
            <configuration>
              <properties>
<!--                <cargo.remote.username>jason</cargo.remote.username>-->
<!--                <cargo.remote.password>password</cargo.remote.password>-->
                <cargo.hostname>192.168.10.22</cargo.hostname>
              </properties>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

解决方法

我猜您需要在 POM 的 <properties> 部分中定义它们,而不是在插件的配置中。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...