views:

372

answers:

1

I am working both in the Ruby and Java worlds. I have been inspired somewhat by the merb-assets project, which provides various functionality to make it easy to reference assets (images, CSS, etc.) located on a subdomain (or CDN).

I want to do the same in Java:

  • in development and testing, I want to use either JSTL's <c:url> or Struts 2's <s:url value=""/> tags to reference assets.
  • but in production, I want to move most of these assets out to a separate subdomain (or CDN).

Are there any taglibs (or other methodologies) out there that can help with this? I don't particular want to litter my views with <c:if and tests for localhost, everytime I insert an <img> or <link> tag.

I am using Struts 2 + JSP.

+1  A: 

I don't really know Struts 2, but I am thinking of a solution that involves the use of Maven2 features... So, in the case you are indeed using Maven2 to build your application, you may solve your problem with the resources filter and profiles features.

Resources filtering: You can ask Maven2 to filter ressources files (in our case, the JSP files). Filter means to replace all ${xxx} by their value. This will be useful to replace a parameter (${domain.url} for example) by the value you need to have ("localhost", "http://...").

Then, you define 2 profiles: "development-test" and "production". Each profile will define its own domain for these assets. For example, in development-test, you can define the domain as "localhost", in production, the domain will be "http://....".

I am not sure if this can solve your problem, but you can give it a try :o)

References : Filter resources: http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html Profiles: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

romaintaz
I am fully invested in using Maven 2, so this solution looks interesting (although completely different from the solutions I had envisaged!). 2 questions: 1. does filtering conflict with JSTL variables? 2. how can I configure this if I want my JSPs to remain in my WEB-INF/ folder?
myabc