Installing Apache Tomcat on OS X Yosemite - mhulse/mhulse.github.io GitHub Wiki
There’s a couple of solutions for local Apache Tomcat development on a Mac.
I prefer, and suggest, option #3 below.
Though, before installation, install and setup Java.
-
Go here and install Java. This installs the “Web” plugin. Alternatively, download the Java installer from Apple (here’s the one for Yosemite) and you will have access to development tools like
javac
(for command line compilation). -
Add this to your
.bash_profile
:# Oracle version (no javac): export JAVA_HOME='/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home' # Apple version (includes javac): export JAVA_HOME=$(/usr/libexec/java_home) # Pick or or other of the above. # Check my .bash_profile for real world example: # https://github.com/mhulse/dotfizzles
-
Reload your profile (or, restart computer):
$ source ~/.bash_profile
The above steps apply to all options listed below.
One advantage to using the Bitnami Tomcat installer is that it comes with:
- Apache 2.4.10
- Apache Tomcat 7.0.57
- MySQL 5.5.40
- Apache Ant 1.8.1
- Ant-Contrib 1.0b3
- PHP 5.4.34
- PHPMyAdmin 4.2.9.1
-
Download and install the Bitnami “Tomcat 8.0.18-0 Dev (64-bit)” OS X installer (or, get the version that matches the version on the live server).
-
Once installed, symlink your version-controlled JSP app to the
webapps
folder of the Tomcat installation. For example, I keep my repos in~/github/organization-or-team
:$ ln -s ~/github/organization-or-team/repo/ /Applications/tomcatstack-7.0.57-0/apache-tomcat/webapps/
-
Next, open
tomcatstack-7.0.57-0/manager-osx.app
, click on the “Manager Servers” button and start “Apache Web Server” and “Tomcat Server”.Alternatively, you can use the command line:
$ cd /Applications/tomcatstack-7.0.57-0/ $ ./ctlscript.sh start $ ./ctlscript.sh stop $ ./ctlscript.sh restart # Or, by the service: # ./ctlscript.sh (start|stop|restart) apache # ./ctlscript.sh (start|stop|restart) mysql # ./ctlscript.sh (start|stop|restart) tomcat
Check out the README.txt
file at the root of Bitnami’s Tomcat install for more useful information.
You can install Tomcat using Homebrew.
I don’t recommend this …
Why? Because once you install Homebrew's version of Tomcat, you have to edit Brew-installed Tomcat files … I don't like the thought of touching Brew's packages directly, so I don't think using Brew to run Tomcat is the best option.
$ brew install tomcat
# Reload your profile:
$ source ~/bash_profile
# Start or stop Tomcat:
$ catalina start
$ catalina stop
# View available commands:
$ catalina -h
I consider this to be the best middle-ground option because:
- It does not come with all of the overhead as the Bitnami installer.
- It’s easier to edit core files, unlike the Homebrew option.
-
Make sure Java is installed and
JAVA_HOME
environment variable is available. -
Visit http://tomcat.apache.org/.
-
Click on the latest Tomcat version in the sidebar under Download heading.
-
Under Core download the
zip
binary distribution. -
Put the extracted folder anywhere on your HDD (I put mine in
/Applications
). -
Create an alias to Tomcat:
$ ln -s apache-tomcat-8.0.18 tomcat
-
Make
catalina
script executable:$ chmod a+x /Applications/tomcat/bin/catalina.sh
-
Add this line to your
.bash_profile
:# http://tomcat.apache.org/ export CATALINA_HOME='/Applications/tomcat' # Make this an alias.
-
Add this function to your
~/.bash_functions
:# Shortcut function to control Apache Tomcat Catalina script: catalina() { # Long-hand version: # Start: # $CATALINA_HOME/bin/startup.sh # ... or: # $CATALINA_HOME/bin/catalina.sh start # Stop: # $CATALINA_HOME/bin/shutdown.sh # ... or: # $CATALINA_HOME/bin/catalina.sh stop # See .bash_aliases for related alias. if [ -z $1 ]; then OPTION=start else OPTION=$1 fi $CATALINA_HOME/bin/catalina.sh OPTION }
-
Add this alias to your
~/.bash_aliases
:# Apache Tomcat: alias tomcat=catalina
Use the above alias to run any other Tomcat
catalina
commands. -
Reload your profile:
$ source ~/.bash_profile
. -
Symlink your JSP app:
$ ln -s ~/github/organization-or-team/repo-name/ /Applications/tomcat/webapps/repo-name/
Tomcat
7.x
: If you have any issues with getting symlinked apps to work, navigate to/Applications/apache-tomcat-7.0.78/webapps/
and create a directory namedMETA-INF
and create a file, within this directory, namedcontext.xml
; copy/paste the following into this file:<?xml version="1.0" encoding="UTF-8"?> <Context path="/myapp" allowLinking="true"> </Context>
Restart Tomcat.
-
Add this to
/Applications/apache-tomcat-7.0.78/conf/tomcat-users.xml
, right before the closing</tomcat-users>
:<role rolename="manager-gui"/> <user username="tomcat" password="" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status"/>
-
Start or stop Tomcat:
# Start: $ tomcat # ... or (redundant): $ tomcat start # Stop: $ tomcat stop
-
Visit http://localhost:8080/app-name and your app should load; you may need to include a
WEB-INF/
orMETA-INF/
depending on your JSP/JAVA application needs.
Check the RUNNING.txt
file at the root of the Tomcat install for more useful information (like, tailing the `logs/catalina.YYY-MM-DD.log log files if you run into any issues).
:)