I just want to configure jetty to listen to more than one port. I don't want multiple instances nor multiple 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!
jetty , by default, it runs on port 8080, in root context '/'. 2.2 Change a different context path, set seconds to check for changes and automatically hot redeploy. 2.3 Change a different port to start.
Changing a Jetty Server PortEither double click the port, or use the content menu. In the Port Number field, replace the current port number, 8080, with the new port number, in this example, 8081. In the main Eclipse toolbar, click File -> Save. You have changed the port.
jetty. xml is the default configuration file for Jetty, typically located at $JETTY_HOME/etc/jetty. xml.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With