在集成测试中使用的 jetty-maven-plugin 7.x 可以在运行时动态查找可用端口。我该如何保存找到的端口号并在Java集成测试中使用它?也许 jetty-maven-plugin 可以将其保存到系统变量中?
以下是其工作原理:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<portNames>
<portName>jetty.port</portName>
<portName>jetty.port.stop</portName>
</portNames>
</configuration>
<executions>
<execution>
<id>reserve-port</id>
<phase>pre-integration-test</phase>
<goals>
<goal>reserve-network-port</goal>
</goals>
</execution>
</executions>
</plugin>
然后可以使用${jetty.port}
来配置Jetty插件。
${jetty.port}
,你可以通过使用systemPropertyValues
将其传递给Surefire插件:http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html - sleske