Enable JSP files on port 80 in OS X Server

Feb 04, '05 09:19:00AM

Contributed by: mnoriega

After googling and searching in macosxhints.com without finding a solution, I finally got this to work, so I hope this may help others. The problem I had was that I could not get JSP files to be served on port 80. When I started Tomcat, I could only see Tomcat's examples, which are on port 9006. There may be a better solution, but being new to Tomcat, this is how I solved it. If someone else has a better solution I'd be happy to hear from you.

Here's what I did:

  1. Enable the jk_module for Apache. This is activated in Server Admin -> Web -> Setting -> Modules. Select the enabled checkbox by the jk_module and hit Save. This will restart the Apache server.

  2. Copy from /Library/Tomcat the conf, logs, temp, webapps and work directories to your sites folder -- e.g. /Library/WebServer/Documents. You should now have:
    /Library/WebServer/Documents/conf
    /Library/WebServer/Documents/logs
    /Library/WebServer/Documents/temp
    /Library/WebServer/Documents/webapps
    /Library/WebServer/Documents/work
    
    Each directory would have all their contents, too.

  3. I created a web directory to hold my jsp files (/Library/WebServer/Documents/web). And placed my JSP files in there.

  4. You'll need to run a new instance of Tomcat on port 80, so you need to edit you new server.xml file for your Tomcat instance:
    pico /Library/WebServer/Documents/conf/server.xml
    
    Find where it says port 9006 and change it to port 80. You'll also need to change the examples directory your "web" directory for Tomcat to look for JSP files. Find:
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
                   port="9006" minProcessors="5" maxProcessors="75"
    
    Replace with:
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
                   port="80" minProcessors="5" maxProcessors="75"
    
    Find:
            <!-- Tomcat Examples Context -->
            <Context path="/examples" docBase="web" debug="0"
                     reloadable="true" crossContext="true">
    
    Replace with:
            <!-- Tomcat Examples Context -->
            <Context path="/web" docBase="web" debug="0"
                     reloadable="true" crossContext="true">
    
    Find:
    WebAppDeploy examples warpConnection /examples/
    Replace with:
    WebAppDeploy web warpConnection /web/
  5. Create a script called mytomcat.sh to start Tomcat using your website folder as base directory:
    #!/bin/sh
    
    # set the environment
    
    CATALINA_BASE=/Library/WebServer/Documents
    CATALINA_HOME=/Library/Tomcat
    JAVA_HOME=/Library/Java/Home
    JAVA_OPTS=-server
    
    export CATALINA_BASE CATALINE_HOME JAVA_HOME JAVA_OPTS
    
    exec "$CATALINA_HOME"/bin/catalina.sh "$@"
    
  6. Give mytomcat.sh execute permisions":
    chmod 755 mytomcat.sh
    
  7. Restart Tomcat.
    sudo ./mytomcat.sh stop
    sudo ./mytomcat.sh start
    
That's it, you should now be able to run jsp files from your site: http://www.yourdomain.com/web/test.jsp

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050202163402976