What's a good way to parameterize "static" content (e.g. CSS) in a Tomcat webapp?

Posted by Steven Huwig on Stack Overflow See other posts from Stack Overflow or by Steven Huwig
Published on 2010-04-27T14:04:09Z Indexed on 2010/04/27 14:23 UTC
Read the original article Hit count: 223

Some of our CSS files contain parameters that can vary based on the deployment location (dev, QA, prod). For example:

 background: url(#DOJO_PATH#/dijit/themes...)

to avoid hardcoding a path to a particular CDN or locally-hosted Dojo installation.

These values are textually substituted with the real values by a deployment script, when it copies the contents of the webapp into the Tomcat webapps directory. That way the same deployment archive file (WAR + TAR file containing other configuration) can be deployed to dev, QA, and prod, with the varying parameters provided by environment-specific configuration files.

However, I'd like to make the contents of the WAR (including the templatized CSS files) independent of this in-house deployment script. Since we don't really have control over the deployment script, all I can think to do is configure Tomcat with #DOJO_PATH# etc. as environment variables in the application's context.xml, and use Tomcat to insert those parameters into the CSS at runtime.

I could make the CSS files into generated JSPs, but it seems a little ugly to me. Moreover, the substitution only needs to be done once per application deployment, so repeatedly dynamically generating the stylesheets using JSP will be rather wasteful.

Does anyone have any alternative ideas or tools to use for this? We're committed to Tomcat and to substituting these parameters at deployment or at runtime (that is, not at build time).

© Stack Overflow or respective owner

Related posts about jsp

Related posts about tomcat