Neil Ang

Bersonal Plog

A stunning likeness of Neil Ang
Super Nerd

How to install Tomcat on Mac OS X

Posted on .

A while back I wrote a post on the ubuntu forums on how to install Tomcat on ubuntu. It was very popular (if I do say myself) so I thought I would post the instructions on how to setup tomcat on Apple's OS X. These instructions work for 10.4 (Tiger), 10.5 (Leopard) and 10.6 (Snow Leopard).

Installing Tomcat

  1. Download the latest core binary distributions of tomcat from http://tomcat.apache.org/ (do not download the windows service installer).
  2. Unzip the download and rename the folder from "apache-tomcat-x-x-xx" to something simple like "Tomcat".
  3. Move the folder to the root /Library directory (or somewhere else convenient). Tomcat is installed. That's it!
  4. To start tomcat run startup.sh found in /Library/Tomcat/bin. To stop tomcat run shutdown.sh found in the same bin directory. After starting tomcat navigate to http://localhost:8080 to see if the server is working.

Custom Tomcat Start/Stop Script

To make starting and stopping tomcat easier you can create a custom shell script to turn tomcat on and off through terminal.

Open up your favorite text editor (mine is TextMate) and add the following code:

#!/bin/bash

case $1 in
  start)
    sh /Library/Tomcat/bin/startup.sh
  ;;
  stop)
    sh /Library/Tomcat/bin/shutdown.sh
  ;;
  restart)
    sh /Library/Tomcat/bin/shutdown.sh
    sh /Library/Tomcat/bin/startup.sh
  ;;
  *)
    echo "Usage: start|stop|restart"
  ;;
esac

exit 0

Save the file with the title "tomcat" (in lowercase and no extension). Place the file in a bin directory which is included in your terminal's path e.g. /usr/bin. Now when you want to use tomcat, simply write "tomcat start" and "tomcat stop" in terminal.

Leave a comment if you have any suggestions, troubleshooting or ideas.