Search code examples
javajavascriptdeploymentear

How can one deploy common JavaScript and images to two different EARs while not having to maintain two versions of each file


I have a Struts web app deployed to an EAR that has some pretty extensive JavaScript. I now need to create a new web app that will be deployed to a new EAR but will probably need to share most if not all of the JavaScript and some images from the first application. What's the best way to avoid code duplication so I don't have to put a copy of each JavaScript file in each EAR in my development environment?


Solution

  • You could maintain the Javascript in a separate .jar library and serve it as a resource, not as a static file. That way the JS content would be a regular dependency in your project setup. Unfortunately there isn't a straightforward universal way to do this because you need at the very least a servlet that will send the file from the .jar. (Depending on your web framework you might already have this available.)

    This also has some performance implications, but for a line of business application you probably don't need to optimize the load time of your internal Javascripts all that heavily.

    Another alternative would be doing this at the source control level, using something like Git submodules.