How to set server port with org.eclipse.jetty:jetty-maven-plugin?
Solution 1
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:
-
Set the property inside your project pom.xml descriptor file:
<properties> <jetty.http.port>9999</jetty.http.port> </properties>
-
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.
Solution 2
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.
Solution 3
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>
Solution 4
This works for me, confirmed as I am currently debugging the server in my chrome on port 8088.
mvn jetty:run -Dhttp.port=8088
carlspring
I am a Senior Build, Release and Deployment Engineering contractor (with some seven years in the field). I am also a Senior Java Developer (with well over ten years behind me). I am into source control management, tooling, continuous integration, research and development and other odd things most developers wouldn't want to get into. :) I am active in the Open Source community, by hosting several of my own projects, as well as discussing or contributing fixes for various OSS projects. I believe in OSS and that contributing to the online society via either free tools or advice on various problems will not only strengthen one's own knowledge, but also help others advance as well.
Updated on July 05, 2022Comments
-
carlspring almost 2 years
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 anhttpConnector
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 ajetty.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
. -
Lucky almost 9 yearsThe system property
jetty.port
din't work for me. However the httpConnector worked. Can you also please add the jetty-maven-plugin documentation?. -
tmarwen almost 9 yearsThanks @Lucky for pointing that out. I think the
jetty.port
property is now depreacated in favor ofjetty.http.port
. The answer has been updated to mirror changes in the plugin documentation. -
Admin almost 8 yearsI have no luck with -Djetty.http.port=9999 but with -Djetty.port=9999 instead
-
carlspring almost 8 yearsHow is this answer any different, or better than the accepted one?
-
Espinosa over 7 yearsConfirmed, with plugin.jetty.maven.version=9.1.4.v20140401 it is jetty.port; jetty.http.port, from accepted answer, des not work.
-
Zakaria Bouazza over 6 yearsThanks 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!
-
carlspring over 6 yearsFor the reference of future users: which version of the plugin are you using? (Could you specify the GAV coordinates)?
-
Satya Singh over 6 yearsafter adding above code in your pom.xml file access the jetty server in any browser using localhost:8888
-
sonu about 4 yearsthe above code goes in the plugins -> plugin -> configuration tags of pom.xml file
-
Jeremy Caney about 4 yearsUnder 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.