In Jetty 8.1.17.v20150415 I am using the org.eclipse.jetty.server.Connector.getLocalPort()
method to determine which random HTTP port my Jetty is listening on, using the following line of code:
int port = server.getConnectors()[0].getLocalPort();
However, when I upgrade to a Jetty 9.x (9.3.3.v20150827), I find the getLocalPort()
method doesn't exist any more. What is the replacement?
It looks like that's now in NetworkConnector
(which extends Connector
) - presumably because some connectors don't run over a network.
If you know that your server will be using a NetworkConnector
, you could presumably use:
NetworkConnector networkConnector = (NetworkConnector) server.getConnectors()[0];
int port = networkConnector.getLocalPort();
See more on this question at Stackoverflow