Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Running Tomcat on

...

Mac OS X

For an updated guide for installing Tomcat 5/6 on Mac OS X 10.6 using MacPorts check http://serverfault.com/questions/183496/full-guide-for-installing-tomcat-on-os-x

Wiki Markup
\[See below for later updates to this 2004 posting\]

...

I hope these notes are of use to someone out there.

THE ENVIRONMENT

The following assumes you have Java already is installed - it should be installed by default on every MacOS X installation. Note that MacOS MacOS X 10.2 (Jaguar) comes with Java 1.3; MacOS X 10.3 (Panther) comes with Java 1.4. MacOS X 10.4 (Tiger) comes with Java 1.4.2 installed, but Java 1.5 can be downloaded. MacOS X 10.5 (Leopard) comes with Java 1.5. MacOS X 10.5 (Snow Leopard) comes with Java 1.6. It is possible to run Java 1.4 on MacOS X Jaguar but it may interfere with operation of the standard environment.

...

I just named it Tomcat as it saves some typing in the Terminal (smile)

So the directory structure becomes:

Macintosh HD > Library > Tomcat > <extracted files>

Step 3: Configure JAVA_HOME

We then need to set the JAVA_HOME environment variable - this is almost the same as setting the Windows XP environment variable.

Doing this is easiest and best done with additional software to assist in setting the environment variables.

Recommended software is the preference pane RCEnvironment (http://www.rubicode.com/Software/RCEnvironment/)

Copy the RCEnvironment Preference Pane to Macintosh HD > Library > Preference Panes.

Go to System Preferences and click on Environment Variables.

The environment variable JAVA_HOME should be defined as /Library/Java/Home.

To do this, in the left hand column enter JAVA_HOME and in the right hand column enter /Library/Java/Home. Click Apply.

So the directory structure becomes:

Macintosh HD > Library > Tomcat > <extracted files>

Step 3Step 4: Configure tomcat-users.xml

...

No Format
 <?xml version='1.0' encoding='utf-8'?>
 <tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="tomcat" password="tomcat" roles="tomcat,admin,manager"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
 </tomcat-users>

In this case a role, a user and password have been set up with the name tomcat. You can change this later.

Step 5: Reboot

Reboot (or login again, at least). This sets up the environment and cleans out any extras you still have running. It sets up JAVA_HOME as well.

a user and password have been set up with the name tomcat. You can change this later.

Step 4Step 6: Start Tomcat

To start Tomcat, open a shell command prompt (using, for instance, the Terminal application).

...

Any file in this directory ending in .sh can be executed in the terminal by putting a period and a slash before the file name (eg: startup.sh). The following example executes the tomcat startup script:

No Format
./startup.sh && tail -f ../logs/catalina.out

Terminal should display four lines looking something like this:

No Format
Using CATALINA_BASE:   /library/tomcat
Using CATALINA_HOME:   /library/tomcat
Using CATALINA_TMPDIR: /library/tomcat/temp
Using JAVA_HOME:       /Library/Java/Home
Users-Computer:/library/tomcat/bin user$ 

...

 

There are some notes and a couple of Preference Panes for automating the starting and stopping of Tomcat. After trying them all on five different computers - this is the simplest!

Step 75: Test installation Open a browser window, and enter http://127.0.0.1:8080 - the default Tomcat page should open.

...

  • But I did need to fix vital file permissions in the downloaded Tomcat folder.

Also Updated in 2010

By Pid: I removed some of the original statements about setting JAVA_HOME as they did not match my experience of installing Tomcat on OS X. It's also certainly overkill to install an application just to be able to set an environment variable.

(1) Upgrade to Mac OS X 10.4.6

...

(3) Fix the Unix file permissions

  • Download the freeware BatChmod, a GUI wrapper around the Unix "chmod" command.

...

  • Drag and drop the entire Tomcat folder onto the BatChmod icon.
  • Check *all* the checkboxes.

...

  • Add a rule to do port-forwarding from port 80 to Tomcat's default port 8080. Type this in the Terminal:
    No Format
    sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to any 80 in
    
    Or use this nifty program, another GUI wrapper around the ipfw command line, Simple Port Forwarder: http://www.4dresources.com/files/

The Sharing SysPref will get cranky when you add an ipfw rule behind its back; it disables its user interface. To use the Sharing SysPref again you'll have to clear that rule, the one we added and numbered 100. To delete a rule, either read the ipfw man page, or use Simple Port Forwarder again. Quit the System Preferences program, and re-launch it to re-enable its Firewall panel.

...

To have Tomcat 6.0.x launch on boot on Mac OS X 10.5.x, you need to add a LaunchDaemon. Create a file called org.apache.tomcat.plist in /Library/LaunchDaemons/ with the following content:

...

Inside this, create two files - Tomcat (script) and StartupParameters.plist. Again, make them writable only by root, and the script executable by everyone.

Contents of StartupParameters.plist:

No Format
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Description</key>
	<string>Tomcat Server</string>
	<key>OrderPreference</key>
	<string>Late</string>
	<key>Provides</key>
	<array>
		<string>Tomcat</string>
	</array>
	</dict>
</plist>

...

No Format
#!/bin/sh
#
# /Library/StartupItems/Tomcat/Tomcat
#
# A script to automatically start up Tomcat on system bootup
# for Mac OS X. This is actually just a wrapper script around
# the standard catalina.sh script, which is included in
# the distribution.
#

# Suppress the annoying "$1: unbound variable" error when no option
# was given
if [ -z $1 ] ; then
	echo "Usage: $0 [start|stop|restart] "
	exit 1
fi

# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common

# The path to the catalina.sh script. 
# The currently used version is in /Library/Tomcat/Home/bin
SCRIPT="/Library/Tomcat/Home/bin/catalina.sh"

# file to hold the process ID on start so it can be killed by stop.
export CATALINA_PID="/Library/Tomcat/Home/server.pid"

StartService ()
{
	if [ "${TOMCAT:=-NO-}" = "-YES-" ] ; then
		ConsoleMessage "Starting Tomcat server"
		$SCRIPT start > /dev/null 2>&1
	fi
}

StopService ()
{
	ConsoleMessage "Stopping Tomcat server"
	$SCRIPT stop -force > /dev/null 2>&1
}

RestartService ()
{
	ConsoleMessage "Restarting Tomcat server"
	StopService
	StartService
}

if test -x $SCRIPT ; then
	RunService "$1"
else
	ConsoleMessage "Could not find Tomcat control script!"
fi

...

CategoryFAQ