gpt4 book ai didi

java - 自动启动/停止前端测试的 Web 服务器

转载 作者:行者123 更新时间:2023-11-30 08:28:53 25 4
gpt4 key购买 nike

现在,我通过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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com