Skip Navigation

Installing Apache Tomcat on Mac OS X

By Robert Crews

This document describes installing Apache Tomcat on Mac OS X. When complete, Tomcat will start up along with the operating system, will be integrated with the Apache web server built into the operating system, and will be fully controllable with the standard Mac OS X SystemStarter utility.

Apache Tomcat, the reference implementation for Java's servlet technology, was written by James Duncan Davidson—creator of Ant, author of Ant: The Definitive Guide, Running Mac OS X Panther, Running Mac OS X Tiger, Mac OS X Panther Hacks, Cocoa in a Nutshell, Learning Cocoa with Objective-C, 2nd Edition, and major contributor to Ruby on Rails—while he was working as a software architect for Sun Microsystems from 1997 to 2001. He was instrumental in getting Sun to release the software as open source and donate the source code to the Apache Software foundation.

For Tomcat 4, Craig McClanahan—creator of Apache Struts and member of the expert group responsible for the 2.2 and 2.3 Java servlet specifications and the 1.1 and 1.2 JSP specifications—significantly enhanced Tomcat's servlet implementation, calling it "Catalina." Tomcat 4 also included a major upgrade to the JSP processor called "Jasper." (Think of a tool that works on a JSP—"jasp"—as a jasper… or not.)

In addition to architectural and functional improvements, major Tomcat releases coincide with Tomcat's implementation of updates to the Java servlet and JSP specifications. Tomcat is popular because is it easy to install, easy to manage, and easy to integrate with the Apache web server. It has good standards compliance, many useful features, and is relatively fast.

Creating the Apache Tomcat User and Group

To create the Apache Tomcat user and group:

  1. Run the following from the Mac OS X command line:

    $ sudo dscl . -create /groups/tomcat ;\
    sudo dscl . -create /groups/tomcat Password "*" ;\
    sudo dscl . -create /groups/tomcat PrimaryGroupID 498 ;\
    sudo dscl . -create /groups/tomcat RealName "Apache Tomcat Users" ;\
    sudo dscl . -create /users/tomcat ;\
    sudo dscl . -create /users/tomcat Password "*" ;\
    sudo dscl . -create /users/tomcat UniqueID 498 ;\
    sudo dscl . -create /users/tomcat PrimaryGroupID 498 ;\
    sudo dscl . -create /users/tomcat RealName "Apache Tomcat Server" ;\
    sudo dscl . -create /users/tomcat NFSHomeDirectory /var/empty ;\
    sudo dscl . -create /users/tomcat UserShell /usr/bin/false
    

    See the dscl man page for more information.

  2. Hide the tomcat user (and all other users with a UniqueID less than 500) from the Mac OS X GUI:

    $ sudo defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool true
    

Building and Installing Apache Tomcat

...

To install Apache Tomcat:

  1. Get Apache Tomcat source and unpack it into /usr/local.

    $ pushd .;
    cd /usr/local ;\
    sudo curl -O \
    http://www.apache.org/dist/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz ;\
    sudo tar xvfz apache-tomcat-6.0.18.tar.gz ;\
    sudo chown tomcat:tomcat apache-tomcat-6.0.18 ;\
    sudo ln -s apache-tomcat-6.0.18 apache-tomcat ;\
    popd
    
  2. Create a file containing the following data at /Library/LaunchDaemons/org.apache.tomcat.plist:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
      "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Disabled</key>
        <true/>
        <key>EnvironmentVariables</key>
        <dict>
            <key>CATALINA_HOME</key>
            <string>/usr/local/apache-tomcat</string>
            <key>CATALINA_OPTS</key>
            <string>
                -server
                -Xmx256m
                -Dfile.encoding=UTF-8
                -Djava.awt.headless=true
                -Duser.language=en
                -Duser.timezone=America/Los_Angles
            </string>
            <key>JAVA_HOME</key>
            <string>/Library/Java/Home</string>
        </dict>
        <key>KeepAlive</key>
        <dict>
            <key>SuccessfulExit</key>
            <true/>
        </dict>
        <key>Label</key>
        <string>org.apache.tomcat</string>
        <key>ProgramArguments</key>
        <array>
            <string>/usr/local/apache-tomcat/bin/catalina.sh</string>
            <string>run</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>UserName</key>
        <string>tomcat</string>
    </dict>
    </plist>
    

    The Disabled key—set to "true" above—controls whether or not Apache Tomcat will automatically start when your computer boots. Disabled true means it will not start automatically. The launchctl command provides a -w command flag to set or unset the Disabled flag without requiring you to edit the file in a text or XML editor.

  3. Start Apache Tomcat:

    $ sudo launchctl load -w /Library/LaunchDaemons/org.apache.tomcat.plist
    

    Note the presence of the -w flag that removes the org.apache.tomcat.plist Disabled flag, configuring Apache Tomcat to automatically launch when your computer boots.

See http://www.malisphoto.com/tips/tomcatonosx.html