现在,我通过maven单独启动嵌入式tomcat:
mvn tomcat7:run
然后运行 mvn test
目标。
我的问题是我可以配置 maven 以便自动执行此操作吗?
tomcat
必须在所有测试运行之前启动,然后停止。
使用了tomcat插件的以下maven配置:
<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>
但这并没有帮助
最佳答案
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>
关于java - 自动启动/停止前端测试的 Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19886816/