现在,我通过 maven 启动单独嵌入的 tomcat:
mvn tomcat7:run
然后运行mvn test
目标。我的问题是我可以配置 Maven 以自动执行此操作吗?
tomcat
必须在所有测试运行之前启动,然后停止。
使用以下 maven 配置的 tomcat 插件:
<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>
我尝试将插件配置更新为:
<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>
但这没有帮助