How to set server port with org.eclipse.jetty:jetty-maven-plugin?

carlspring picture carlspring · Sep 3, 2014 · Viewed 48.6k times · Source

I am currently setting the port via a jetty.xml file and I've been trying to figure out from the new documentation how to actually define an httpConnector through the Maven plugin's configuration. The docs on Eclipse's site seem a bit vague on it and I've been trying to figure this out for a while, thus ending up using a jetty.xml. I'd like to find out the proper way to do this now.

I'm currently using org.eclipse.jetty:jetty-maven-plugin:9.2.1.v20140609.

Answer

tmarwen picture tmarwen · Sep 5, 2014

The jetty-maven-plugin documentation states that you can either configure the httpConnector element in the pom.xml file to setup the ServerConnector preferences or use the jetty.http.port system property to change the port or use the Jetty descriptor i.e. the way you are doing it actually. And then you have several options:

  • Change the port when just at runtime:

    mvn jetty:run -Djetty.http.port=9999
    
  • Set the property inside your pom.xml file:

    <properties>
      <jetty.http.port>9999</jetty.http.port>
    </properties>
    

    Then just run:

    mvn jetty:run
    
  • Set the port in your plugin declaration inside the pom.xml file:

    <build>
      <plugins>
        <plugin>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>9.2.1.v20140609</version>
          <configuration>
            <httpConnector>
              <!--host>localhost</host-->
              <port>9999</port>
            </httpConnector>
          </configuration>
        </plugin>
      </plugins>
    </build>
    

EDIT

In new versions of jetty-maven-plugin, jetty.http.port is deprecated and won't work. You can try jetty.port if the instruction above doesn't work.