Main Tutorials

How to change Tomcat default port ?

Tomcat by default runs on port number 8080, However there is high chance get a port conflict with others program. Sometime we just need to change the Tomcat port number.

Steps of changing the Tomcat Port

1) Locate server.xml in {Tomcat installation folder}\ conf \

2) Find following similar statement


 <!-- Define a non-SSL HTTP/1.1 Connector on port 8180 -->
    <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />

or


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

3) About Tomcat’s server.xml file cites it’s runs on port 8080. Change the Connector port=”8080″ port to any other port number.

For example


 <Connector port="8181" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

Above statement instruct Tomcat server runs on port 8181.

4) Edit and save the server.xml file. Restart Tomcat. Done

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
44 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
suvarna
3 years ago

I want to setup SSL but getting issue of connector is failed to initialize 

Mogu
4 years ago

Hi

We have configured TOMEE ( apache-tomee-plus-7.0.5) in redhat linux. The situation here is we forced to use http port number as 80 instead of 8080 in the server.xml config file.

When we run startup.sh script with “root” user , the server is started fine without any issues. if i try to use my user id to start the server giving error “Failed to initialize connector” as below.

Kindly help me how to fix this issue.

11-Jun-2019 22:47:36.749 INFO [main] sun.reflect.DelegatingMethodAccessorImpl.invoke Initializing ProtocolHandler [“http-nio-10.177.122.10-80”]
11-Jun-2019 22:47:36.757 SEVERE [main] sun.reflect.NativeMethodAccessorImpl.invoke Failed to initialize connector [Connector[HTTP/1.1-80]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-80]]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
at org.apache.catalina.core.StandardService.initInternal(StandardService.java:549)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:875)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
at org.apache.catalina.startup.Catalina.load(Catalina.java:632)
at org.apache.catalina.startup.Catalina.load(Catalina.java:655)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:309)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
at org.apache.catalina.connector.Connector.initInternal(Connector.java:995)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
… 12 more
Caused by: java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:463)
at sun.nio.ch.Net.bind(Net.java:455)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210)
at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:1086)
at org.apache.tomcat.util.net.AbstractJsseEndpoint.init(AbstractJsseEndpoint.java:268)
at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:581)
at org.apache.coyote.http11.AbstractHttp11Protocol.init(AbstractHttp11Protocol.java:68)
at org.apache.catalina.connector.Connector.initInternal(Connector.java:993)
… 13 more

11-Jun-2019 22:47:36.758 INFO [main] sun.reflect.DelegatingMethodAccessorImpl.invoke Initializing ProtocolHandler [“ajp-nio-8009”]

Arman Ahmed
5 years ago

For maven

jst write in the plugin

org.apache.tomcat.maven
tomcat7-maven-plugin
2.2

/
true
9966

Guest
6 years ago

After Delopying different war in tomcat, how set different port number to all deployed wars

Kos Petoussis
8 years ago

brilliant. you are awesome!

Lakmal udayanga Balasooriya
8 years ago

Thanks mate It work like charm 😀

Vanisri Patro
8 years ago

hello freind,

Please help me…I have tomcat in xampp whose default port no=8080 but at that port I am running oracle…when I am trying to change the port no of tomcat…again it is saying that tomcat is in 8080 port no but it is not so..

Here is the snapshot of server.xml where i changed to 9000….is it ok.


<!–
–>

Salisu Suleiman Umar
8 years ago

I like how Mr. Mkyong give a good simple explained that help and i will also help other as a developer.
Thanks…Thanks…Thanks.

Jayashree
9 years ago

Hi,

I need to several modules for an application.

Now all are running under 8080.

URL looks like : http://localhost:8080//statuscheck/ http://localhost:8080/reports/.
I want reports alone to be moved to some other port. I tried aading another service in the server.xml. But it doesnt work.
Any help would be appreciated.
Regards,
Jayashree

Jayani
9 years ago

Thank you! This works 🙂

Vlad
9 years ago

Great guide but I had to change the debug port (default 8000) from startup.bat. Now I can run 2 instances of tomcat in parallel. Thank you !

Anon Nimo
9 years ago

Amazing, very easy to follow and complete guide like always! thank you

Saurabh Agrawal
9 years ago

is there any command by which we can customize this port?

vignesh
9 years ago

thanks budyy it really works

Rahul Danwade
9 years ago

hi ,
I have changed my apache tomcat port no to 8181 and 9090 but server was not able to start.
I have also checked log files and it shown BindException can you suggest me how to get rid of it.

lynas
9 years ago
Reply to  Rahul Danwade

Need to see stack trace to help you out. or ask about that in stackoverflow

Ranjeet Ranjan
10 years ago

Hi,
My application is running on http://msizzler.com:8080/lin/ but I want it should run on http://msizzler.com/lin/ please let me know how I can do that.

szlynas
9 years ago
Reply to  Ranjeet Ranjan

rename your application war file to ROOT.war

imran
10 years ago

thank you verry much .so solved my unending problems……

Joann Fabrics coupon codes
10 years ago

Hello I am so glad I found your weblog, I really found
you by mistake, while I was looking on Google for something else, Regardless I am here now and would just like to say thanks a lot
for a remarkable post and a all round entertaining blog (I also love the theme/design), I don’t have time to go through it all at the moment but I have saved it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the great work.

Vxb This coupon
10 years ago

My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using WordPress on
a number of websites for about a year and am anxious about switching to another platform.
I have heard great things about blogengine.net. Is there a way I can import all my
wordpress content into it? Any kind of help would be greatly appreciated!

douglas
10 years ago

Hi there are using WordPress for your site platform?
I’m new to the blog world but I’m trying to get started and create
my own. Do you require any coding expertise to make your own blog?
Any help would be greatly appreciated!

clara
11 years ago

thank u so much.it is now working properly.

Rakesh K Satyam
11 years ago

Thanks

Vijaya
11 years ago

Great! Thanks a lot for your effort and help.

Jomblick J
11 years ago

Should we change shutdown port also? what is the purpose of that shutdown port ??

Shivam
11 years ago

thanks a lot. Its working properly……

rahul
11 years ago

thanks a lot, it is working very fine.

siva
12 years ago

great….but not working for me….iam encountering some more problems……pls help me

ildolce
12 years ago

Hi.

I have a problem.
I’ve changed the port in server.xml because I have this port with other application.
I start tomcat server from catabalina.bat perfect in the new port.
I change the port for tomcat in XAMP.INI with the new port.
Restart the computer.
And I try again to start tomcat server from XAMP console but I see log as “Busy port – Tomcat 8080”.
The tomcat server start but I want to avoid this message in the xamp console.

What Can I do?

Ruby
12 years ago

Nice tutorial. I love your site..
Some more similar tutorial that may help others
http://www.raistudies.com/tomcat/change-port-number-of-tomcat-server/

Thank You

servletworld
13 years ago

Nice tutorial, This tutorial explains how to change the HTTP port, shutdown port and AJP port http://www.servletworld.com/tomcat/howto-change-tomcat-port.html