how to configure jetty to listen to multiple ports
I just want to configure jetty to listen to more than one port. I don't want multiple instances nor mult开发者_开发百科iple webapps, just one jetty, one webapp, but listening to 2 or more ports.
The default way does not support multiple entries:
<Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
Thank you for your help!
In your jetty.xml file, add a new connector:
<!-- original connector on port 8080 -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8080"/></Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
<!-- new connector on port 8081 -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host"><Property name="jetty.host" /></Set>
<Set name="port"><Property name="jetty.port" default="8081"/></Set>
<Set name="maxIdleTime">300000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="lowResourcesConnections">20000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
Then start jetty
java -jar start.jar etc\jetty.xml
Should do what you want.
And if using Jetty in embedded mode, you can open multiple ports in your Java code:
Server server = new Server();
Connector c1 = new SelectChannelConnector();
c1.setPort(8080);
Connector c2 = new SelectChannelConnector();
c2.setPort(8081);
/* ... even more ports ... */
Connector[] ports = {c1, c2 /* ... */};
server.setConnectors(ports);
精彩评论