如何在Maven 3中运行嵌入式Tomcat 9进行集成测试?

如何在Maven 3中运行嵌入式Tomcat 9进行集成测试?,maven,tomcat9,cargo,maven-cargo,Maven,Tomcat9,Cargo,Maven Cargo,为了集成测试的目的,我尝试在Maven 3中运行嵌入式Tomcat 9。我被其他SO答案引导到了cargo-maven2-plugin 因此,尝试按照此处的说明进行操作: 我在一个简单的POM中有这个片段: <build> <plugins> <plugin> <groupId>org.codehaus.cargo</groupId> <artifactId

为了集成测试的目的,我尝试在Maven 3中运行嵌入式Tomcat 9。我被其他SO答案引导到了
cargo-maven2-plugin

因此,尝试按照此处的说明进行操作:

我在一个简单的POM中有这个片段:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.7.6</version>
            <configuration>
                <container>
                    <containerId>tomcat9x</containerId>
                    <type>embedded</type>
                </container>
                <deployables>
                    <deployable>
                        <type>war</type>
                        <properties>
                            <file>path/to/myapp.war</file>
                        </properties>
                    </deployable>
                </deployables>
            </configuration>
        </plugin>
    </plugins>
</build>

org.codehaus.cargo
cargo-maven2-plugin
1.7.6
tomcat9x
嵌入的
战争
路径/to/myapp.war
我尝试使用
mvn org.codehaus.cargo:cargo-maven2-plugin:run执行它

它失败并出现以下错误:

[INFO][en2.ContainerRunMojo]已解析的容器工件 cargo:cargo核心容器tomcat:jar:1.7.6用于容器 tomcat9x[警告]定义的可部署组件具有相同的groupId和 artifactId作为项目的主要工件,但类型不同。 当项目的打包为[pom]时,您已经定义了[war]类型。 这可能是一个错误,因此插件将尝试 在项目的依赖项中找到此可部署项


我怎样才能做到这一点?我只想在Maven内部的嵌入式tomcat9中启动给定的战争。

在尝试了许多排列之后,这终于对我起作用了:

        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.7.9</version>
            <configuration>
                <container>
                    <systemProperties>
                        <myvar1>${myEnvVar}</myvar1>
                        <myvar2>... stuff ...</myvar2>
                    </systemProperties>
                    <containerId>tomcat9x</containerId>
                    <zipUrlInstaller>
                        <url>https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/9.0.29/tomcat-9.0.29.zip</url>
                    </zipUrlInstaller>
                </container>
                <deployables>
                    <deployable>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>simple-war</artifactId>
                        <type>war</type>
                        <location>path/to/myapp.war</location>
                        <properties>
                            <context>myapp</context>
                        </properties>
                    </deployable>
                </deployables>
                <executions>
                    <execution>
                        <id>start-server</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-server</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </configuration>
        </plugin>
            <plugin>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.21.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>
                </executions>
            </plugin>