How to start and stop the Apache tomcat server in command line

Apache Tomcat Server

Apache tomcat server is a open source web server that is developed by Apache software foundation. It allows to run servlet and Java Server Pages(JSP) based web applications. It provides HTTP server environment for the Java code to run.It has the build in servlet container called Catalina in the tomcat bin directory. It handles HTTP requests such as instantiate the GET and POST method’s object .

Start the Apache tomcat server in command line

The tomcat bin directory contains all the start and shutdown script. First we need to navigate to the Apache tomcat bin directory as below. Then we can run the startup script that will start the Apache tomcat server.

Apache tomcat bin direcotry

Stop the Apache tomcat server in command line

There is a shutdown script in the Apache tomcat bin directory. We can run this script to stop the Apache tomcat server as below.

Check the logs in the Apache tomcat server

Once we start the Apache tomcat server, It will create lot of log files in the logs directory. The Catalina.out file is the important log file that contains our Java application logs.

Kill the process that running in port 18080

If you want to kill the process that runs on port 18080, You can get the process id by running the command as lsof -i <port number> and Kill the same using kill -9 <PID> command as below.

To run our Java application on Apache tomcat server

We need to set an environment variable CATALINA_HOME to the path of the directory into which we have installed Tomcat. Then we can run our application on the Apache tomcat server. The below sample script is used to run the Java application in the Apache tomcat server.

Recommended Articles