How to change Tomcat default port from 8080?

By default, Tomcat will be configured to listen the port number 8080 for all the HTTP request, but there are many situations where other Java applications also uses the same 8080 port number which will result in Java Bind Exception.

java.net.BindException: Address already in use: JVM_Bind: 8080

In order to prevent those exceptions we need to change tomcat default port from 8080 to something else like 9090 (or) 9091. In this article lets see how we can change the tomcat default port.

How to change Tomcat default port from 8080?

Step1 : 

Find out tomcat’s server.xml, usually it will be under C:\Program Files\Apache Software Foundation\Tomcat\conf if tomcat is installed in the default location. If not traverse through the installation path under conf folder you will have server.xml

Step 2:

Locate the below line in the server.xml 

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

Here you can see the port number is configured to 8080.

Step 3:

Change the default port (8080) to 9090 or something of your choice.

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

Step 4:

Save the server.xml file and restart tomcat. You could see that tomcat will be listening to 9090 instead of 8080. Like below

Apr 09, 2015 3:46:37 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9090"]
Apr 09, 2015 3:46:37 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]

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

Step 5:

Even when you hit on the url “http://localhost:9090” in your browser you should see tomcat start-up page. It means that your tomcat is listening to 9090 not to 8080.

How to change Tomcat default port from 8080 in Eclipse?

It will be much easier for us to change tomcat default port in eclipse,  In the Servers view, double click on the server name

change Tomcat default port

Now you will be getting the configuration page of tomcat, wherein which you can see all the port numbers which tomcat is listening to

Tomcat Configuration Page

 

Under the Ports module, HTTP/1.1 click on the port number, you can see it will be in editable simply change it to the desired one (9090)change Tomcat default port in eclipse

Press Ctrl + S to save the change that we have made and restart the server. You can see that the port number will be modified in the console view.

Tomcat changed port

Leave a Reply

Your email address will not be published. Required fields are marked *