Question

Now, I start separately embedded tomcat via maven:

mvn tomcat7:run

And then run the mvn test goal. My question is can I configure maven in order to do that automatically? tomcat has to be started before all tests run, and then stopped.

The following maven configuration for tomcat plugin is used:

        <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <path>/SpringMvcExample</path>
                <url>http://localhost:8080/manager/text</url>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>

I've tried to update the plugin configuration to:

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <path>/SpringMvcExample</path>
            <url>http://localhost:8080/manager/text</url>
            <server>tomcat7</server>
        </configuration>
        <executions>
            <execution>
                <id>start-tomcat</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>
            <execution>
                <id>stop-tomcat</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>shutdown</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

But it did not help

Was it helpful?

Solution

        attach tomcat:run to pre-integration-test
        attach tomcat:shutdown to post-integration-test
Below is the code snippet. 
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
       <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
                <configuration>

                    <fork>true</fork> 
                </configuration>

           </execution>
           <execution>
            <id>tomcat-shutdown</id>
            <goals>
              <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
          </execution>
        </executions>
      </plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top