Tuesday, July 27, 2021

How to change Tomcat default port 8080? Example Steps

Tomcat default port is 8080 but many times other Java application also uses 8080 like any other web-server Resin or Jetty and starting tomcat may result in java.net.BindException:Address already in use: JVM_Bind 8080. In order to avoid this exception you can change default port of tomcat from 8080 to some other port e.g. 8081 or 8082. Though don't change to tomcat port which is likely to be used by tomcat itself e.g. 8443 is used by tomcat https port. Use port which is most likely to be free. In this tomcat tutorial we will see how to change default port 8080 for http protocol in tomcat and port 8443 port for https protocol in tomcat.



How to change Tomcat default port 8080

Step by step guide to change tomcat default port 8080

change tomcat default port 8080 for http and httpsHere is step by step guide to change tomcat default port 8080

Step 1:
Find out tomcat server.xml its generally in "C:\Program Files\Apache Software Foundation\Tomcat\conf". This is tomcat installation directory and could be different on your computer based on tomcat version. But important point is server.xml will be inside conf folder


Step 2:
Tomcat uses Connector element to specify port numbers, just locate the relevant Connector element in Server.xml which is configured to listening on port 8080. You can do this by using UNIX grep command on 8080 or simply find following text:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="30000"
               redirectPort="8443" />

This Statement is saying that tomcat is listening on 8080 port.

Step 3:
Change default tomcat port from 8080 to 8081 or 8082 in Server.xml file of tomcat

    <Connector port="8082" protocol="HTTP/1.1"
               connectionTimeout="30000"
               redirectPort="8443" />

Now tomcat will listen on Port 8082 instead of default port 8080.

4. save your changes on the server.xml file and restart the tomcat web server. It will start listening on port 8082 instead of on default port 8080.

5. Type http://localhost:8082 in your browser you should see the tomcat start-up page; it means your tomcat server is configured to listen to http traffic on 8082 instead of default 8080.

How to change the tomcat default port for SSL or HTTPS

Now you know how to change tomcat default port 8080 for http traffic you can also change default SSL port 8443 which is used by HTTPS protocol. Just find out the relevant section of the connector element using grep or find command and change the port from 8443 to 8553 or something else.



How to change default SHUTDOWN Port of Tomcat

Tomcat web server has a concept of SHUTDOWN port, this is the port on which tomcat web-server listens for SHUTDOWN signal. This is another cause of Java.net.BindException: Address already in use: JVM_Bind:8005 because sometimes other application also listens on same default SHUTDOWN port 8005.
Just like the default tomcat port, you can also change the tomcat SHUTDOWN port, and here is a step by step example

Step: 1 Find out the SHUTDOWN Section in Server.xml
Use the find or grep command to find word "SHUTDOWN" which will bring you to:

<Server port="8005" shutdown="SHUTDOWN"/>

Now just change the SHUTDOWN port from 8005 to any other port you want.

That’s all on how to change the tomcat default port from 8080 for both http and HTTPS. Let me know if you face any problems while changing the default tomcat port.

Related Java Tutorials

3 comments :

Roshni said...

hi I want my tomcat 6 to execute web application on http://localhost, I don't want to type 8080 again and again , is there any way I can do this ? I read somewhere that I can do this by changing the default port of tomcat 6 to 80 but as soon as I did this by following your method I got Java.net.BindException: Address already in use: JVM_Bind:80 , What should I do now ,please suggest ?

Alam said...

You need to shutdown the server which is already listening on port 80, probably this would be your "Apache server" or "IIS" or may be some times the wireless printers use this port (80)

Anonymous said...

Another method you can use is iptables. iptables let you forward traffic received on one port (80) to another port (8080). This method bypasses the Apache webserver completely (even if it is running on port 80). This is the simple to setup. But you will not be able to use Apache (e.g. for webmail, using PHP apps, or apps like phpMyAdmin)

Post a Comment