Apache Tomcat : Installation and application deployment basics

apache-tomcat-logo

Tomcat is a web application server in which you can run Java applications, or in other words used to deploy your Java Servlets and JSPs. In this tutorial we will learn to install Tomcat in a Redhat host using the yum repositories.

Install tomcat and related applications:
[root@gw16-lap-devops ~]# yum install tomcat tomcat-webapps tomcat-admin-webapps -y

Start tomcat server
[root@gw16-lap-devops ~]# systemctl start tomcat

  • Once the tomcat server is up and running, which may take couple of minutes, you can access the tomcat dashboard using the URL “http://gw16-lap-devops:8080/
  • This gives an interface to manage your tomcat server. However to use full features of this portal, such as the once that can be accessed by clicling the button “Manager App“, etc, you will require an admin account, which can be created by editing the file “/etc/tomcat/tomcat-users.xml“.
  • At the end of the file “/etc/tomcat/tomcat-users.xml” add following line (copy and paste):
    <user name=”admin” password=”adminadmin” roles=”admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status” />
  • Now restart the tomcat server to load the new configuration
    [root@gw16-lap-devops ~]# systemctl restart tomcat

 

  • You can manage the web applications loaded in the server by going to the tomcat server dashboard (http://gw16-lap-devops:8080/), and clicking the button “Manager App

How to deploy a new application in the server:

  • Tomcat server requires the Java servlet files (.jsp) to be packaged along with “web.xml” in “.war” format. Let us name this file myApp.war. An example to create a “.war” file can be found in this link.
  • This newly created war file (for example myApp.war) needs to be copied to the webapps folder “/var/lib/tomcat/webapps/
  • Very soon you will see a new folder created named “myApp” there in which the content of the “myApp.war” will be extracted.
  • Restart tomcat server
  • A link to manage the new web application will be found in theĀ “Manager App” that can be reached via the Tomcat server’s bashboard that is accessible via “http://<hostname>:8080
  • The uploaded application can be see by accessing the URL “http://<hostname>:8080/myApp/<jsp file created with .jsp extension>