Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

maven

jetty

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.

like image 579
carlspring Avatar asked Sep 03 '14 12:09

carlspring


People also ask

How do I change the port for Jetty in eclipse?

To modify the Jetty server port, open the Jetty v7. 0 Server at localhost, The Ports section is on the Overview tab (right panel). Either double click the port, or use the content menu. In the Port Number field, replace the current port number, 8080, with the new port number, in this example, 8081.

What is the Artifactid of Jetty maven plugin?

1.1 The 'groupId' is org. eclipse. jetty , by default, it runs on port 8080, in root context '/'.


2 Answers

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.

like image 134
tmarwen Avatar answered Sep 17 '22 09:09

tmarwen


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.

like image 20
Vivek Garg Avatar answered Sep 21 '22 09:09

Vivek Garg