Installing Apache Tomcat on Mac OS X
Apache Tomcat Run Simple or Enterprise-Level Java
Web Applications with Apache
Tomcat on your Mac

While the capabilities of Apache Web Server and PHP are almost limitless, there are many advantages to developing web applications in Java. The power and portability of the Java Virtual Machine is being used more and more to its seemingly unlimited potential every year. The J2EE APIs provide an enormous amount of useful, reusable code, and the increasing prevalence of Servlets and Servlet Frameworks such as Struts all provide ample reason for a software developer to explore the capabilities of Java on the Web.

To that end, the simplest way to utilize Java in a Web application is through the use of Servlets and Java Server Pages. These both require the installation of a Servlet container that provides a bridge or translation layer between the raw HTTP request and the server-side processing in Java. These Servlet containers come in various forms, but the easiest to get started for the beginner is the Apache Foundation's open-source Tomcat servlet container. Installing it on the Mac OS X platform could not be easier.

1. Download and unpack the Tomcat binary file

Tomcat is available from the Apache Web Site. At the time of this article (April, 2009), the latest version was 6.0.18 and available here: Tomcat 6.0.18 tar.gz

While it doesn't matter where you save it, now is the time to decide where you want Tomcat to run. An older Tomcat/Mac tutorial suggests /usr/local, but I prefer a more distinct location, so I created a /Tomcat directory at the root of my development drive. Move the file there and unpack it.

Development:/ username$ cd /
Development:/ username$ sudo mkdir Tomcat
Password:
Development:/ username$ sudo chown -R username:admin Tomcat
Development:/ username$ mv ~/Desktop/apache-tomcat-6.0.18.tar.gz /Tomcat
Development:/ username$ cd /Tomcat
Development:/ username$ gnutar -xzvf apache-tomcat-6.0.18.tar.gz

If you don't want to fuss with the Terminal commands, in Finder simply navigate to the directory where you want Tomcat to reside using the Go to Folder command. Drag the apache-tomcat-6.0.18.tar.gz file to that location and unpack it by double-clicking on it.

2. Starting Tomcat

The hard part is over. Now you will need to create two scripts for starting and stopping Tomcat. The first is the startup script. Copy and paste the following code into a text editor that uses UNIX line endings, and save the file as start_tomcat. This script file should probably be located in your home directory somewhere. I like using a standard ~/bin directory.

#!/bin/sh
export CATALINA_HOME=/Tomcat/apache-tomcat-6.0.18
export JAVA_HOME=/usr
$CATALINA_HOME/bin/startup.sh

Next is the shutdown script. Save the following as stop_tomcat in the same location as the startup script.

#!/bin/sh
export CATALINA_HOME=/Tomcat/apache-tomcat-6.0.18
export JAVA_HOME=/usr
$CATALINA_HOME/bin/shutdown.sh

Make the two files executable for user and group by running the following in Terminal.

Development:/ username$ chmod ug+x ~/bin/start_tomcat ~/bin/stop_tomcat

Now using the start_tomcat script you just created, you can start Tomcat by running the following in Terminal.

Development:/ username$ ~/bin/start_tomcat

If all went as expected, you will have successfully installed Apache Tomcat on your Mac OS X platform, and you should be able to navigate to http://localhost:8080 and see the Tomcat startup page.

Look around at the resources and example applications that are supplied with Tomcat and reachable from the local Tomcat home page. It won't be long before you are creating your own Servlets, JSPs, and million-dollar Web Applications.

Good Luck.


Written and Maintained by: Eric Jankowski
ericjankowski@me.com