Change Jetty default port

隐身守侯 提交于 2019-11-30 04:46:23
Magnus Lassi

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

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 runnging at 9090 port than default 8080 port. Then do "curl -i -XGET "http://localhost:9090". That should give you 200 http status. Thats it.

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

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

Haidong Zhang

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

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

Just for completeness on jetty 7 you can use this:

java -jar start.jar --module=http jetty.port=9080
Haseeb Ahmad

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!