71

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.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
carlspring
  • 31,231
  • 29
  • 115
  • 197

6 Answers6

151

The jetty-maven-plugin documentation (for jetty 11 at the time of this answer - update) 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.

Then you have several options:

(Java) System Property:

Change the port when just running your application through the mvn command:

mvn jetty:run -Djetty.http.port=9999

(Maven) Project Property:

  1. Set the property inside your project pom.xml descriptor file:

     <properties>
       <jetty.http.port>9999</jetty.http.port>
     </properties>
    
  2. Then just run your application through the Jetty plugin and the port will be picked up automatically:

    mvn jetty:run

(Maven) Jetty Plugin Configuration:

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 the default port property and jetty.port won't work as in previous plugin versions.

tmarwen
  • 15,750
  • 5
  • 43
  • 62
  • The system property `jetty.port` din't work for me. However the httpConnector worked. Can you also please add the jetty-maven-plugin documentation?. – Lucky Sep 03 '15 at 08:11
  • 2
    Thanks @Lucky for pointing that out. I think the `jetty.port` property is now depreacated in favor of `jetty.http.port`. The answer has been updated to mirror changes in the plugin documentation. – tmarwen Sep 04 '15 at 11:15
  • 3
    I have no luck with -Djetty.http.port=9999 but with -Djetty.port=9999 instead –  Jul 27 '16 at 17:11
  • Thanks a lot! Just to say that in Intellij it got it wrong, guess it is a bug. But it works fine running the command mvn! – Zakaria Bouazza Oct 04 '17 at 07:43
25

Run following command: mvn jetty:run -Djetty.port=9999

I guess mvn jetty:run -Djetty.http.port=9999 is deprecated. It didn't work for me.

Vivek Garg
  • 2,115
  • 1
  • 20
  • 17
17

You may configure the port through the pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.1.v20140609</version>
            <configuration>
                <httpConnector>
                    <port>9999</port>
                </httpConnector>
            </configuration>
        </plugin>
    </plugins>
</build>
Benjamin
  • 1,816
  • 13
  • 21
2

This works for me, confirmed as I am currently debugging the server in my chrome on port 8088.

 mvn jetty:run -Dhttp.port=8088
lukeDevBE
  • 21
  • 1
  • 1
    For the reference of future users: which version of the plugin are you using? (Could you specify the GAV coordinates)? – carlspring Oct 18 '17 at 15:42
0

By Default Jetty runs on 8080 port, if any application like oracle DB using that port in your system then Jetty server will not start and gives some BIND exception. to overcome this if your project is maven project then in pom.xml file use below code, then it works perfectly(here i am using port 8888 which is free in my system)

<!-- The Jetty plugin allows us to easily test the development build by
                running jetty:run on the command line. -->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.plugin.version}</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                     <httpConnector>
                    <host>localhost</host>
                     <port>8888</port>
                     </httpConnector>
                </configuration>
            </plugin>
  • after adding above code in your pom.xml file access the jetty server in any browser using http://localhost:8888/ – Satya Singh Mar 22 '18 at 10:24
0
<connectors>
    <connector>
        <port>9999</port>
    </connector>
</connectors>

in pom.xml file

sonu
  • 1
  • the above code goes in the plugins -> plugin -> configuration tags of pom.xml file – sonu Jun 28 '20 at 12:18
  • 1
    Under your answer, there is a small link titled "edit". You can use that to modify your answer. Please update your answer with the explanation from your above comment. – Jeremy Caney Jun 28 '20 at 23:30