1

我尝试使用 cargo-maven2-plugin 来自动化我的 WAR 模块部署以进行测试。

我想知道如何启动 tomcat 服务器(预装在我的机器中)并将我的战争自动部署到启动的服务器上?

Cargo 项目的文档提到 cargo:start 目标可以选择部署可部署:

http://cargo.codehaus.org/Maven2+plugin#Maven2plugin-gettingstarted

cargo:start 启动一个容器。该任务可以选择安装和配置容器;它还可以选择性地向其部署可部署项(WAR、EAR 等)。

但是,我不知道如何启用此选项以使其在运行 cargo:start 时部署可部署。

这是我当前的 pom 配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0</version>
            <configuration>
                <wait>true</wait>
                <container>
                    <containerId>tomcat6x</containerId>
                    <home>${tomcat.home}</home>
                </container>
                <configuration>
                    <type>standalone</type>
                    <home>target/tomcat6x</home>
                </configuration>
                <deployer>
                    <deployables>
                        <deployable>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>my-war</artifactId>
                            <type>war</type>
                        </deployable>
                    </deployables>
                </deployer>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>my-war</artifactId>
        <version>${project.version}</version>
        <type>war</type>
    </dependency>
</dependencies>

当我运行“mvn cargo:start”时,将启动 tomcat 服务器,但是不会部署 my-war deployable。我必须从另一个 shell 运行“mvn cargo:deploy”来部署这场战争。

4

1 回答 1

2

OK -- There are a few things going on here:

1) You mention that the Tomcat server is pre-installed on the machine, but yet you have the directory specified in your target directory. This is not a good idea as that will get wiped out after a mvn clean.

2) For pre-installed Tomcat you are not setting the type to existing inside the deployer configuration.

3) Where is your context definition? Do you have a context fragment file or are you using a tomcat.xml file inside the WEB-INF directory in the WAR?

Bottom line a combination of configuration errors are holding you back. Post an updated Maven configuration and addition details about the XML context definition and I can help you further.

于 2011-02-08T02:26:45.630 回答