Installing Apache Tomcat

To take advantage of additional functionality, we can install some packages that would allow us to control the application server from a web interface as well as have example applications and the documentation to Tomcat available. To install the additional packages, we execute the following command in a “root” shell.

apt-get install tomcat7-admin tomcat7-examples tomcat7-docs

Configuring Tomcat Web Interface

To enable access to some of the features, we need to set a username and password for Tomcat in the /etc/tomcat7/tomcat-users.xml file. To define a user “admin” with password “password”, we edit the file to contain the following.

Once we’ve defined the user, we will be able to access the management sections of Tomcat. For these changes to take effect, we need to restart the service by executing the following command in a “root” shell.

service tomcat7 restart

Testing Tomcat Web Interface

To view the Tomcat documentation, we can access it at http://localhost:8080/docs. This will provide us with extensive information on how to perform something with Tomcat.

To view the Tomcat example applications, we can access it at http://localhost:8080/examples. The examples implement a few different technologies that we can use for reference since the source code is included as well.

To view the Tomcat manager web application, we can access it at http://localhost:8080/manager/html, which will allow us to manage the Java applications (start, stop, deploy and reload applications) as well as enable us to find memory leaks in our running applications.

To view the Tomcat host-manager web application, we can access it at http://localhost:8080/host-manager/html, which will allow us to test, adjust and add virtual hosts in order to serve our applications.

Installing the Java Development Tools

To enable us to develop Java applications for Tomcat, we first need to install a compatible Java Development Kit by executing the following command in a “root” shell.

apt-get install default-jdk

This will install the openjdk-6-jdk package on our server. The documentation also suggests that we install Apache Ant, a build tool for Java applications, by executing the following command in a “root” shell.