Apache Tomcat (or simply Tomcat) is an open source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP
) specifications from Oracle Corporation, and provides a “pure Java” HTTP web server
environment for Java code to run.
If you have any of below questions then you are at right place:
- Several ports (8080, 8081, 8082) required by Tomcat Server at localhost are already in use
- Tomcat Server Error – Port 8080 already in use
- port 8080 required is in use
- port 8080 already in use eclipse
- how to stop port 8080 in windows
I’ve setup tomcat as Windows Service
. Running Tomcat as a Windows Service provides a number of benefits that are essential when moving from a development set-up to a production environment.
Benefit-1) Setup reliable automatic startup on boot
- Essential in an environment where you may want to remotely reboot a Java System after maintenance without worrying about whether your server will come back online.
Benefit-2) Setup Tomcat server startup without active user login
- In a data center, it is not reasonable to expect an active login from the system just to run Tomcat. In fact, Tomcat is often run on blade servers that may not even have an active monitor connected to them. Windows Services are owned by the System, and can be started without an active user.
Benefit-3) Better Security
start/stop
my Tomcat Server via command line as wanted to create quick shall script to do it. Official documentation provided below commands in the form of //XX// ServiceName
Available command line options are:
//TS//
Run the service as console application This is the default operation. It is called if the no option is provided. The ServiceName is the name of the executable without exe suffix, meaning Tomcat6//RS//
Run the service Called only from ServiceManager//SS//
Stop the service//US//
Update service parameters//IS//
Install service//DS//
Delete service Stops the service if running
But rather doing it this way I found below commands very useful and simple.
1) Windows (if Tomcat is setup as Windows Service)
- To
Start
server: <Tomcat Root>/bin>Tomcat8.exe start - To
Stop
server: <Tomcat Root>/bin>Tomcat8.exe stop
2) Windows (if you have downloaded binaries as .zip)
- To
Start
server: <Tomcat Root>/bin>catalina.bat start
- To
Stop
server: <Tomcat Root>/bin>catalina.bat stop
3) Mac/Linux/Unix (if you have downloaded binaries as .zip)
- To
Start
server: <Tomcat Root>/bin>./catalina.sh start - To
Stop
server: <Tomcat Root>/bin>./catalina.sh stop
Below are all catalina.sh
command parameters:
Usage: catalina.sh ( commands ... ) commands: debug Start Catalina in a debugger debug -security Debug Catalina with a security manager jpda start Start Catalina under JPDA debugger run Start Catalina in the current window run -security Start in the current window with security manager start Start Catalina in a separate window start -security Start in a separate window with security manager stop Stop Catalina, waiting up to 5 seconds for the process to end stop n Stop Catalina, waiting up to n seconds for the process to end stop -force Stop Catalina, wait up to 5 seconds and then use kill -KILL if still running stop n -force Stop Catalina, wait up to n seconds and then use kill -KILL if still running configtest Run a basic syntax check on server.xml - check exit code for result version What version of tomcat are you running?
Startup Screenshot:
How to check if Tomcat is already running and kill existing tomcat process.
Step-1) Find out the process using command ps -ef | grep tomcat
bash-3.2$ ps -ef | grep tomcat 502 56188 1 0 7:31PM ttys001 0:04.23 /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/bin/java -Djava.util.logging.config.file=/Users/appshah/Downloads/apache-tomcat-8.5.4/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -classpath /Users/appshah/Downloads/apache-tomcat-8.5.4/bin/bootstrap.jar:/Users/appshah/Downloads/apache-tomcat-8.5.4/bin/tomcat-juli.jar -Dcatalina.base=/Users/appshah/Downloads/apache-tomcat-8.5.4 -Dcatalina.home=/Users/appshah/Downloads/apache-tomcat-8.5.4 -Djava.io.tmpdir=/Users/appshah/Downloads/apache-tomcat-8.5.4/temp org.apache.catalina.startup.Bootstrap start 502 56618 55587 0 7:34PM ttys001 0:00.00 grep tomcat
Here 2nd column value is a process ID. In our case it’s 56188
.
You could visit link http://localhost:8080
and you should see welcome page.
Step-2) Kill process using command kill -9 <process ID>
bash-3.2$ kill -9 56188
Here, 56188
is a process ID
which we got it from step-1.
Now, link http://localhost:8080/
shouldn’t be working for you.
hai i have downloaded tomcat binaries as .zip on windows. when i gave like catalina.bat start I am getting an erroe like” The JRE_HOME environment variable is not defined correctly
This environment variable is needed to run this program”. can anyone please help me in solving the problem.
Hi Leena – I’ve just published an article with all detailed steps on how to setup JRE_HOME and JAVA_HOME on windows here: https://crunchify.com/how-to-setup-configure-java-home-and-jre-home-environment-variables-on-windows/
Let me know if you face any issue.
Hai.. It was really helpfull. Thank You.
You are welcome Leena.
We have a Linux script to restart Tomcat (say – when the java code of a website changes). This simple script stops Tomcat, waits 5 seconds, starts Tomcat. Unlike Windows Service, the Linux Shutdown script returns immediately – hence the 5 second delay. After upgrade to Tomcat 8, we find this delay is too short. Is there a way to Stop Tomcat reliably (e.g. return control to the script only on completion / test a port to see if it is stopped / check a pid)? If Tomcat is not stopped when you start a new Tomcat, it will say “port already in use” and only partly start up.
Agree. You would see Port Already in Use. If possible, would you please share script and i’ll try to add graceful shutdown signal.
Really it is as simple as
Cd tomcat home
Shutdown.sh
Sleep 5
Startup.sh
But really the sleep 5 should be replaced with some test of aliveness!
Oh great. Yeah, I thought it’s totally custom with some more complications 🙂 I would say 30 second is good enough.
thanks for your help………Now it’s working fine…
Thanks, it worked for me on my CentOS 7. I found that if I create systemd unit file I will be able to start/stop/restart Tomcat using systemctl. It is really hard to find a fully working script, however I spend few sleepless nights and found one. Thanks for sharing this article.
You are welcome Eric. Thanks for taking a time to drop a line.
Thank you!
Thanks for this great tutorial. Appreciate your work.
Thanks.
We’re a gaggle of volunteers and opening a new scheme in our community. Your web site offered us with valuable information to work on. You’ve performed an impressive activity and our whole community can be grateful to you.
Thanks much for nice word. Keep visiting.
WOW just what I was searching for. Came here by searching for Fat Loss Factor Review
Awesome. Glad you like it.
I would like to add that we can also create multiple tomcat instances by using the java based portable utility which I developed for automating the steps required to edit the server config files.
Awesome. Thanks for sharing.
Thanks for sharing link..