Change the default port in Jetty

The Using Embedded Jetty server entry talks about how to embed a Jetty server using Maven in web application. By default the embedded Jetty server starts at port 8080, some times you might want to change it so that it listens on different HTTP port. I wanted to get Jetty to listen on different port and this is how i configured it

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>7.4.5.v20110725</version>
  <configuration>
    <scanIntervalSeconds>10</scanIntervalSeconds>
    <webAppConfig>
      <contextPath>/ManageContact</contextPath>
    </webAppConfig> 

    <connectors>
      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <port>9000</port>
        <maxIdleTime>60000</maxIdleTime>
      </connector>

    </connectors>
  </configuration>
</plugin>
In this code the connectors element is used for configuring the new port number, in my case i changed it to use port 9000. In the version 6.1 code you would have to configure Jetty like this, name of the SelectorChannelConnector package was different before it was moved to eclipse

<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>20080</port>
</connector>
</connectors>

No comments: