Search code examples
javaeclipsespringmavenmaven-assembly-plugin

Maven module for static files


I have a web application with spring and maven. The application is divided into maven modules. I have an "application-web" module that generates war. Another "application-ear" module that generates an ear. And another "application-static" with css, js and images that generates a zip file.

This would be the outline of my application:

  • application
    • application-web (java code)
    • application-ear
    • application-static (css, js and images)
    • application-resources (language properties)

I want to deploy the eclipse use files of "static" module, instead of using the files in the "application/src/main/webapp" directory. How can I do this? It is possible?


Solution

  • Don't waste your time with unpacking resources, everything works out of the box:

    1. Resource bundles: the are always loaded from the classpath, regardlessly it is exploded (WEB-INF/classes) or compressed (WEB-INF/lib)
    2. Serving static resources: bundle them up in a JAR and use either Tomcat (Servlet 3.0) feature to serve from META-INF/resources, see here or use Spring's built in mvc:resources element.

    Simply add the dependency snippets in your WAR POM and your are done.