Change Jetty default port
Asked Answered
G

13

29

Jetty default port is 8080, but I want to change to default port to some other port (9999).

I read a few tutorials and they said almost all of configuration information is by default maintained in file jetty.xml, this file is located under $JETTY_HOME/etc/. Then, change property jetty.port to 9999. However, when I opened up that file, I couldn't find jetty.port property inside the jetty.xml. I'm currently using Jetty-9.2.1 and the port is at 8080.

I found jetty.port property under jetty-http.xml file. Even though I changed the port to 8090 in the jetty-http.xml file, jetty is still running at port 8080.

jetty.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!-- =============================================================== -->
<!-- Documentation of this file format can be found at:              -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax        -->
<!--                                                                 -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default         -->
<!-- configuration files.                                            -->
<!--                                                                 -->
<!-- For a description of the configuration mechanism, see the       -->
<!-- output of:                                                      -->
<!--   java -jar start.jar -?                                        -->
<!-- =============================================================== -->

<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server"           -->
<!-- Other configuration files may also configure the "Server"       -->
<!-- ID, in which case they are adding configuration to the same     -->
<!-- instance.  If other configuration have a different ID, they     -->
<!-- will create and configure another instance of Jetty.            -->
<!-- Consult the javadoc of o.e.j.server.Server for all              -->
<!-- configuration that may be set here.                             -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <!-- =========================================================== -->
    <!-- Configure the Server Thread Pool.                           -->
    <!-- The server holds a common thread pool which is used by      -->
    <!-- default as the executor used by all connectors and servlet  -->
    <!-- dispatches.                                                 -->
    <!--                                                             -->
    <!-- Configuring a fixed thread pool is vital to controlling the -->
    <!-- maximal memory footprint of the server and is a key tuning  -->
    <!-- parameter for tuning.  In an application that rarely blocks -->
    <!-- then maximal threads may be close to the number of 5*CPUs.  -->
    <!-- In an application that frequently blocks, then maximal      -->
    <!-- threads should be set as high as possible given the memory  -->
    <!-- available.                                                  -->
    <!--                                                             -->
    <!-- Consult the javadoc of o.e.j.util.thread.QueuedThreadPool   -->
    <!-- for all configuration that may be set here.                 -->
    <!-- =========================================================== -->
    <!-- uncomment to change type of threadpool
    <Arg name="threadpool"><New id="threadpool" class="org.eclipse.jetty.util.thread.QueuedThreadPool"/></Arg>
    -->
    <Get name="ThreadPool">
      <Set name="minThreads" type="int"><Property name="threads.min" default="10"/></Set>
      <Set name="maxThreads" type="int"><Property name="threads.max" default="200"/></Set>
      <Set name="idleTimeout" type="int"><Property name="threads.timeout" default="60000"/></Set>
      <Set name="detailedDump">false</Set>
    </Get>

    <!-- =========================================================== -->
    <!-- Add shared Scheduler instance                               -->
    <!-- =========================================================== -->
    <Call name="addBean">
      <Arg>
        <New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
      </Arg>
    </Call>

    <!-- =========================================================== -->
    <!-- Http Configuration.                                         -->
    <!-- This is a common configuration instance used by all         -->
    <!-- connectors that can carry HTTP semantics (HTTP, HTTPS, SPDY)-->
    <!-- It configures the non wire protocol aspects of the HTTP     -->
    <!-- semantic.                                                   -->
    <!--                                                             -->
    <!-- This configuration is only defined here and is used by      -->
    <!-- reference from the jetty-http.xml, jetty-https.xml and      -->
    <!-- jetty-spdy.xml configuration files which instantiate the    -->
    <!-- connectors.                                                 -->
    <!--                                                             -->
    <!-- Consult the javadoc of o.e.j.server.HttpConfiguration       -->
    <!-- for all configuration that may be set here.                 -->
    <!-- =========================================================== -->
    <New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
      <Set name="secureScheme">https</Set>
      <Set name="securePort"><Property name="jetty.secure.port" default="8443" /></Set>
      <Set name="outputBufferSize"><Property name="jetty.output.buffer.size" default="32768" /></Set>
      <Set name="requestHeaderSize"><Property name="jetty.request.header.size" default="8192" /></Set>
      <Set name="responseHeaderSize"><Property name="jetty.response.header.size" default="8192" /></Set>
      <Set name="sendServerVersion"><Property name="jetty.send.server.version" default="true" /></Set>
      <Set name="sendDateHeader"><Property name="jetty.send.date.header" default="false" /></Set>
      <Set name="headerCacheSize">512</Set>
      <!-- Uncomment to enable handling of X-Forwarded- style headers
      <Call name="addCustomizer">
        <Arg><New class="org.eclipse.jetty.server.ForwardedRequestCustomizer"/></Arg>
      </Call>
      -->
    </New>


    <!-- =========================================================== -->
    <!-- Set the default handler structure for the Server            -->
    <!-- A handler collection is used to pass received requests to   -->
    <!-- both the ContextHandlerCollection, which selects the next   -->
    <!-- handler by context path and virtual host, and the           -->
    <!-- DefaultHandler, which handles any requests not handled by   -->
    <!-- the context handlers.                                       -->
    <!-- Other handlers may be added to the "Handlers" collection,   -->
    <!-- for example the jetty-requestlog.xml file adds the          -->
    <!-- RequestLogHandler after the default handler                 -->
    <!-- =========================================================== -->
    <Set name="handler">
      <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
           <Item>
             <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
           </Item>
           <Item>
             <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
           </Item>
         </Array>
        </Set>
      </New>
    </Set>

    <!-- =========================================================== -->
    <!-- extra server options                                        -->
    <!-- =========================================================== -->
    <Set name="stopAtShutdown">true</Set>
    <Set name="stopTimeout">5000</Set>
    <Set name="dumpAfterStart"><Property name="jetty.dump.start" default="false"/></Set>
    <Set name="dumpBeforeStop"><Property name="jetty.dump.stop" default="false"/></Set>

</Configure>

jetty-http.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">

<!-- ============================================================= -->
<!-- Configure the Jetty Server instance with an ID "Server"       -->
<!-- by adding a HTTP connector.                                   -->
<!-- This configuration must be used in conjunction with jetty.xml -->
<!-- ============================================================= -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- =========================================================== -->
  <!-- Add a HTTP Connector.                                       -->
  <!-- Configure an o.e.j.server.ServerConnector with a single     -->
  <!-- HttpConnectionFactory instance using the common httpConfig  -->
  <!-- instance defined in jetty.xml                               -->
  <!--                                                             -->
  <!-- Consult the javadoc of o.e.j.server.ServerConnector and     -->
  <!-- o.e.j.server.HttpConnectionFactory for all configuration    -->
  <!-- that may be set here.                                       -->
  <!-- =========================================================== -->
  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.ServerConnector">
        <Arg name="server"><Ref refid="Server" /></Arg>
        <Arg name="factories">
          <Array type="org.eclipse.jetty.server.ConnectionFactory">
            <Item>
              <New class="org.eclipse.jetty.server.HttpConnectionFactory">
                <Arg name="config"><Ref refid="httpConfig" /></Arg>
              </New>
            </Item>
          </Array>
        </Arg>
        <Set name="host"><Property name="jetty.host" /></Set>
        <Set name="port"><Property name="jetty.port" default="8090" /></Set>
        <Set name="idleTimeout"><Property name="http.timeout" default="30000"/></Set>
        <Set name="soLingerTime"><Property name="http.soLingerTime" default="-1"/></Set>
      </New>
    </Arg>
  </Call>

</Configure>

I was also advised to use an integration test to configure Jetty to use other port. There's a integration-tests.properties file inside the project. Maybe a solution is to set jetty.port to 9999 inside this file?

integration-tests.properties:

host = localhost
port = 9999
Grizel answered 9/7, 2014 at 1:35 Comment(2)
Changing the jetty.port setting inside jetty-http.xml worked for me. Maybe you have another application using port 9999?Trollope
For changing ssl default port: stackoverflow.com/a/72082416Grantgranta
V
35

does it work if you set the port when you start it from the command line like this:

java -jar start.jar -Djetty.port=9999
Voe answered 9/7, 2014 at 1:57 Comment(5)
This doesn't change the default port. After running this line, Jetty still runs under port 8080 when I run java -jar start.jar. I'm looking for a way to permanently change the default port.Grizel
@Grizel I was just wondering if it would make a difference in order to troubleshoot the issue. After I updated jetty/start.d/http.ini and changed the port to 9999 and then run the default settings: java -jar start.jar it starts up on port 9999. If you need to run it from maven then this post may help: linkVoe
The documentation said.. mvn -Djetty.http.port=8181 jetty:run but your suggestion works for me. May be because I have context path defined like this ` <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.14.v20131031</version> <configuration> <webAppConfig> <contextPath>/http</contextPath> </webAppConfig> </configuration> </plugin> `Julianjuliana
mvn -Djetty.port=8181 jetty:run helps you start jetty on port 8181Accredit
BTW if using spring boot with jetty underneath you should use --server.port=8090Adelleadelpho
C
11

I did this in Jetty 9.x version. You need to go to $JETTY_HOME/start.ini file and edit this setting jetty.port.

Lets say that you want to run jetty at 9090 port: Please change jetty.port setting in $JETTY_HOME/start.ini from

jetty.port=8080

to

 jetty.port=9090

Then start jetty using java -jar start.jar option. Then jetty will be running at 9090 port than default 8080 port. Then do curl -i -XGET "http://localhost:9090". That should give you 200 http status.

Thats it.

Consternation answered 11/12, 2015 at 19:21 Comment(0)
U
10

Update:

On Jetty 9.x, jetty.port has been deprecated and you can use jetty.http.port instead, as shown below:

$> cd $JETTY_HOME && java -jar start.jar -Djetty.http.port=8080
Ultann answered 15/3, 2016 at 20:57 Comment(0)
C
7

On jetty 9.2.3.v20140905 it`s need to write in /etc/default/jetty

# JETTY_ARGS
#   The default arguments to pass to jetty.
#   For example
JETTY_ARGS="jetty.port=8080 jetty.spdy.port=8443 jetty.secure.port=443"

but this change only http port. To change https port in jetty 9.2 create ini file $JETTY_HOME/start.d/https.ini

# Initialize module https
#
--module=https
## HTTPS Configuration
# HTTP port to listen on
https.port=8443
# HTTPS idle timeout in milliseconds
https.timeout=30000
# HTTPS Socket.soLingerTime in seconds. (-1 to disable)
# https.soLingerTime=-1

jetty 9.3 in /etc/default/jetty

# JETTY_ARGS
# The default arguments to pass to jetty.
# For example
JETTY_ARGS="jetty.http.port=8080 jetty.ssl.port=443"

or command line parameters -Djetty.http.port=8080 -Djetty.ssl.port=443

Chesser answered 22/7, 2016 at 13:51 Comment(0)
U
4

I changed the port successfully, you can try to edit jetty.port in the file located at $Jetty_home/start.d/http.ini.

Unassuming answered 17/6, 2015 at 7:3 Comment(0)
G
3

You need to change the http port in the start.ini file because it will over-right jetty-http.xml config.Or just comment the line in start.ini and keep your config from jetty-http.xml. In [jetty home]/start.ini

## HTTP port to listen on
#jetty.port=8080
Gatefold answered 24/9, 2015 at 14:29 Comment(0)
F
2

Just for completeness on jetty 7 you can use this:

java -jar start.jar --module=http jetty.port=9080
Feria answered 27/11, 2014 at 17:57 Comment(1)
That's a great answer.Boren
L
2

If you are using eclipse you need to set the run configurations. When you install jetty in eclipse, the default port for jetty is 8080.

So you need to change it into an XML file. If the problem remains, you need to change it in eclipse run configurations.

I hope it works, as it worked for me.

Luminosity answered 15/9, 2018 at 16:8 Comment(0)
F
2

For IntelliJ, this can be done similar to Magnus Lassi's command-line answer.

Run --> Edit Configurations --> Add "-Djetty.port=XXXX", e.g.:

jetty:run-war -Djetty.port=9999
Francescafrancesco answered 23/10, 2019 at 15:8 Comment(0)
V
0

For SSL port you can pass the param:

-Dssl.port=8445

It worked for me.

Valadez answered 24/12, 2019 at 21:35 Comment(0)
L
0

For a spring boot application, inside your application.properties file add
server.port = preferred port number eg. 8082

IMAGE OF PORT CONFIGURATION

Lethargy answered 13/1, 2022 at 9:28 Comment(0)
P
0

I changed the jetty.http.port property in jetty/start.ini and it worked for me!

Parterre answered 13/4, 2022 at 11:12 Comment(0)
G
0

For changing SSL port, you need to change jetty.ssl.port property in below directory:

  • 📁$JETTY_HOME/etc
    • 📄 jetty-ssl.xml
<Configure id="Server" class="org.eclipse.jetty.server.Server">
...
  <Call  name="addConnector">
    <Arg>
      <New id="sslConnector" class="org.eclipse.jetty.server.ServerConnector">
      ...
        <Set name="port"><Property name="jetty.ssl.port" deprecated="ssl.port" default="8443" /></Set>
      ...
      </New>
    </Arg>
  </Call>
...
</Configure>
Grantgranta answered 2/5, 2022 at 4:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.