how to configure jetty to listen to multiple ports

前端 未结 2 1697
北海茫月
北海茫月 2021-01-05 05:44

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

相关标签:
2条回答
  • 2021-01-05 05:53

    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.

    0 讨论(0)
  • 2021-01-05 06:05

    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);
    
    0 讨论(0)
提交回复
热议问题