Serving Java with MAMP

Serving Java with MAMP

This is gleaned from here.

To get Java code to run locally in conjuction with MAMP follow these steps:

  1. Download the latest tomcat binary from here.
  2. Extract and place in your MAMP folder (usually in your application folder).
  3. Rename the tomcat folder (apache-tomcat-X.X.XX) to tomcat (this is just to ease upgrades I think).
  4. Add “/Applications/MAMP/tomcat/bin/startup.sh” to the end of the file /Applications/MAMP/bin/startApache.sh
  5. Add “/Applications/MAMP/tomcat/bin/shutdown.sh” to the end of the file /Applications/MAMP/bin/stopApache.sh
  6. Finally, change the permissions on the following files:
    chmod +x startup.sh
    chmod +x shutdown.sh
    chmod +x catalina.sh
    chmod +x setclasspath.sh
    chmod +x bootstrap.jar
    chmod +x tomcat-juli.jar

The lines in step 4 and 5 could be added to the overall ‘start.sh’ and ‘stop.sh’ but as it requires(?) Apache it doesn’t make sense to have tomcat as a self-contained entity.

Fire up a browser and head to localhost:8080 to see if all that worked.

Here is a script to do steps 4 to 6:

#!/bin/sh

echo "/Applications/MAMP/tomcat/bin/startup.sh" >> /Applications/MAMP/bin/startApache.sh
echo "/Applications/MAMP/tomcat/bin/shutdown.sh" >> /Applications/MAMP/bin/stopApache.sh

chmod +x /Applications/MAMP/tomcat/bin/startup.sh
chmod +x /Applications/MAMP/tomcat/bin/shutdown.sh
chmod +x /Applications/MAMP/tomcat/bin/catalina.sh
chmod +x /Applications/MAMP/tomcat/bin/setclasspath.sh
chmod +x /Applications/MAMP/tomcat/bin/bootstrap.jar
chmod +x /Applications/MAMP/tomcat/bin/tomcat-juli.jar