Running Tomcat on Macintosh OS X
These notes are the result of several weeks playing with different things and asking a LOT of questions on several mailing lists.
I hope these notes are of use to someone out there.
THE ENVIRONMENT
The following assumes you have Java already installed - it should be installed by default on every MacOS X installation. Note that 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. It is possible to run Java 1.4 on MacOS X Jaguar but it may interfere with operation of the standard environment.
Verify the following paragraph! This explanation, however, should be right, or nearly so.
JAVA_HOME
is at /Library/Java/Home
, but this is a link into a directory /System/Frameworks/JavaJVM.Framework/Versions
which is used to switch between versions easily. There is a link Current
and CurrentVersion
which matches up the current Java environment with the appropriate version.
THE SITUATION
I wanted to learn about Java Servlet Pages (JSP) on my Macintosh (with MacOS X). I installed it the first time on a Windows XP Professional system, but my development machine is a Macintosh.
THE SOLUTION
Since I had already installed and played with a separate install of Tomcat (the version installed by Apple's XCode was out of date, as was the version I downloaded from another site), I was ready to give up!
In my case I wanted to get rid of all the other Tomcat installations and start from scratch.
Step 1: Download Tomcat
Download Jakarta Tomcat from the Tomcat home page, and get the binary version - I_downloaded jakarta-tomcat-5.0.27.tar.gz.
Extract the files (unless your browser automatically extracts them).
Navigate (using the Finder) to Macintosh HD > Library.
If there is not already a folder in Macintosh HD > Library called Tomcat, then create one.
If there is already a Tomcat folder (presumably from an out-of-date installation), delete all the files already in that folder.
Step 2: Extract tomcat archive
Copy all the unstuffed files from the jakarta-tomcat-5.0.27.tar.gz download and put all the files into the Tomcat folder.
I just named it Tomcat as it saves some typing in the Terminal
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.
Step 4: Configure tomcat-users.xml
Open the /Library/Tomcat/conf/tomcat-users.xml
file with a plain text editor. The default Tomcat installation only has the basic roles and users set up.
What is configured as default is:
<?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user username="both" password="tomcat" roles="tomcat,role1"/> <user username="role1" password="tomcat" roles="role1"/> </tomcat-users>
An example of what it should look like follows:
<?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.
Step 6: Start Tomcat
To start Tomcat, open a shell command prompt (using, for instance, the Terminal application).
The path to Tomcat via the Finder is Macintosh HD > Library > Tomcat.
But to get to that directory using the Terminal, type in:
cd /Library/Tomcat/bin
Do an ls
- you should see a file called startup.sh
.
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:
./startup.sh
Terminal should display four lines looking something like this:
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$
Wait about 30 seconds.
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 7: Test installation Open a browser window, and enter http://127.0.0.1:8080 - the default Tomcat page should open.
If you click the Tomcat Administrator or Tomcat Manager links in the upper left hand of the default Tomcat page, you will be asked for a user name and password.
As mentioned above, use tomcat for the user name, and tomcat for the password.
By : Brynley Blake (31 August 2004)
With considerable help from Joachim, Tracy, Tom, Samuel and Jonel from the Apple Web and Java Developer mailing lists.