Search code examples
apachetomcat7mod-jk

Apache+Tomcat+jk: serving static resources in a Java EE web app


I recently installed Apache w/s + Tomcat and using jk was able to route requests from apache to t/c. The examples on the net are usually of the form:

JkMount /*.jsp myTC

We have several Java EE applications running on a single instance of tomcat (then why use apache? believe me i have reasons). I figured we could change the context for each of those applications to something like:

/servlet/application1/
/servlet/application2/
/servlet/application3/

and then have something like:

JkMount /servlet/* myTC

This would route the requests to tomcat correctly, however, the question remains how to serve static resources for a standard Java EE application:

/webapp-root
    resources/
       css/
       js/
       images/
    WEB-INF/
       /usual-folder-structure

The questions are:

  1. How to serve resources/ folder from apache? all the applications have their own resources/ folder. I figure resources/ will have to reside 'out' of the war and on apache's doc-root somewhere, but can't figure out the JkMount string.

  2. Is the /servlet/ scheme the 'correct' way to do it? are there patterns I should follow?

I'll appreciate any help, any pointers to resources on the net would be great as I need to read a lot more about this.


Solution

  • (1) The following should be enough:

    JkMount /* myTC
    JkUnMount /resources/* myTC
    

    (2) It's OK. There are many correct solutions. I personally don't like /servlet/ in the URL. It's garbage, especially in this age where URLs are an asset of a website/webapp. I use this scheme:

    JkMount /* myTC
    JkUnMount /*.css myTC
    JkUnMount /*.ico myTC
    JkUnMount /*.jpg myTC
    JkUnMount /*.js myTC
    JkUnMount /*.png myTC
    JkUnMount /*.xml myTC
    JkUnMount /*.zip myTC