0

I've got a project set up using the Maven Cargo plugin to launch Tomcat with my webapp deployed in it, along with some other webapps that are needed for support. This works great. Unfortunately, when I run "mvn cargo:run" it doesn't do a build first, but instead just actually starts Tomcat running the code the last time I did do a build.

Previously I used the tomcat7 plugin instead, and that did do a build first and always ran the current version of the source code. As such, I could change my code and run "mvn tomcat7:run" and know that the code changes had been built and were running.

I can't find any way with the Cargo plugin to make it do this, but is there some way with Maven to make it at least run the Package phase when I run a specific plugin so that it will build the WAR file correctly first?

Graham
  • 4,095
  • 4
  • 29
  • 37

3 Answers3

1

The Tomcat plugin automatically invokes the compile phase prior to executing itself. The Cargo plugin won't do that. In order to compile your code before executing the plugin, you need to run

mvn clean compile cargo:run

If you want to start and stop the container automatically before and after your integration tests, you can also bind cargo:start and cargo:stop to Maven's lifecycle phases. See Automatically executing and stopping the container when running mvn install for details.

hzpz
  • 7,536
  • 1
  • 38
  • 44
  • I know you can do that. It was just a bit frustrating that I need to do that for Cargo when I didn't need to do that for Tomcat7 was all. – Graham Jul 17 '15 at 08:32
  • This is how the Maven Cargo plugin works. The developers obviously chose another path than the Tomcat7 plugin guys. – hzpz Jul 17 '15 at 08:59
0

Here is a full example how to integrate the start via Cargo in the usual build. https://github.com/khmarbaise/maui/tree/master/src/main/resources/it-example-container. You can start the integration tests via mvn -Prun-its clean verify which might be better

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I don't want it for integration tests. I want it to start the container so that I can then actually do manual testing in a browser. And that all works absolutely fine. It just doesn't rebuild the WAR file first. – Graham Jul 17 '15 at 08:32
0

A completely different approach would be to use the exec-maven-plugin to execute multiple goals with one command:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.4.0</version>
            <configuration>
                <executable>mvn</executable>
                <arguments>
                    <argument>clean</argument>
                    <argument>compile</argument>
                    <argument>cargo:run</argument>
                </arguments>
            </configuration>
        </plugin>
        <!-- more plugins... -->
    </plugins>
</build>

This way, you would only have to call

mvn exec:exec

to clean, compile and run your application.

hzpz
  • 7,536
  • 1
  • 38
  • 44