-->
Skip to main content

How to Change Port Number In Tomcat in 2021

How to Change Port Number In Tomcat in 2021

Everyday now and then developers face one problem that port 8080 is already in use thus we have to change the port number of our server, Today we will see how to change port number in tomcat.

In the earlier tutorial, we have covered how to add tomcat server in eclipse.

How to Change Port Number in Tomcat
How to Change Port Number in Tomcat

1. How to Change Port Number in Tomcat

Go to the directory where you have downloaded your tomcat server 
For example : C:\Abhishek\Abhishek\java\servers\apache-tomcat-9.0.37
Now go to the conf folder 

Apache Tomcat Server Path
Apache Tomcat Server Path
Now you will see server.xml file under conf folder as shown below

Apache Tomcat Server Xml
Apache Tomcat Server XML
Now opens the server.xml file and search for port="8080" in server.xml file which will take us to this line. 

Apache Tomcat Server Connector Port
Apache Tomcat Server Connector Port

Now change the tomcat default port from 8080 to 9000 or any port you want above 7070 which is unique. Now this  will be lik

Apache Tomcat Server Connector Port Change
Apache Tomcat Server Connector Port Change
Now we are done with apache tomcat port change. Now we will start the server.
To start the server simply goes to  C:\Abhishek\Abhishek\java\servers\apache-tomcat-9.0.37\bin folder

Apache Tomcat Server Bin Path
Apache Tomcat Server Bin Path
Search for Startup.bat in the bin folder.

Apache Tomcat Server Startup File Path
Apache Tomcat Server Startup File Path
Logs will appear which show server started

Apache Tomcat Server Startup Logs
Apache Tomcat Server Startup Logs
Now our server start successfully at port 9000 and we will see the output: 

Apache Server Tomcat Server Output
Apache Server Tomcat Server Output
Horray!!! That's it we have successfully done with our task.

2. How to Change Tomcat Port Number in Eclipse

Now we will see how to change tomcat port number in eclipse. We have covered how to add tomcat server in eclipse in an earlier tutorial. 

We will now see the apache tomcat server that we configured in an earlier post in servers tab like below

Apache Tomcat Server Configured in Eclipse
Apache Tomcat Server Configured in Eclipse
When we double click on this then it shows tomcat server information in this we can see under Ports section we have

HTTP/1.1 pointing to 9000 so we change it to 9001 now or any other port you want.

Apache Tomcat Server Port Changed in Eclipse
Apache Tomcat Server Port Changed in Eclipse

Now save the settings that we change using CTRL+S or Go to File > Save.

Now its show time we will start the server and verify our port changes.

To start the Server, we can either simply press Ctrl+Alt+R or right-click on the servers tab and then click on the start menu option. 

Start Tomcat Server
Start Tomcat Server
Server logs look like below

Apache Tomcat Server Output Logs
Apache Tomcat Server Output Logs
Now we will verify our server that it should show us the output at http://localhost:9001.

Apache Tomcat Server Output At Changed Port
Apache Tomcat Server Output At Changed Port
and that's it for how to change tomcat port number in eclipse.

Conclusion

In this tutorial, we have covered how to Change Port Number in Tomcat from tomcat installation and How to change tomcat port number in eclipse.

Eclipse used it this Project creation is Eclipse IDE 2020-06 With JDK 14. We can simply download eclipse from Eclipse official site

Thanks for reading this tutorial so far. If you like this tutorial then please share it with your friends and colleagues. If you have any questions, doubts, suggestions, or feedback then please drop a comment and I'll try to answer your question.

So what do you think about this simple process to change tomcat port? It's Easy Right?

Comments