jetty-maven-plugin 7.x, when used in integration testing, dynamically finds available port, in runtime. How can I save the number of the port found and use it in Java integration tests? Maybe jetty-maven-plugin can save it into a system variable?
Asked
Active
Viewed 2,416 times
1 Answers
4
This is how it works:
<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>
Then ${jetty.port}
can be used for jetty plugin.

yegor256
- 102,010
- 123
- 446
- 597
-
3As an addition: To use the `${jetty.port}` in your Java tests, you can pass it into the Surefire plugin using `systemPropertyValues`: http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html – sleske Sep 23 '11 at 14:44
-
Keep in mind that using the jetty-maven-plugin goal of "run" will result in the build helper executing twice which might screw up your tests since it will reserve new ports and filter the files again. Switch to "start" to avoid this. – massfords Jul 03 '12 at 15:41