This document outlines an easy way to create JS-based artifacts and use those at runtime in your web applications.You can use Maven's dependency mechanism in your Java web application module POMs to include JS based artifacts and other static resources for use at runtime. The resources will be discovered at runtime by JavascriptDependencyFilter. JavascriptDependencyFilter can be configured to cache and even gzip resources according to configuration, as well as make lazagnia (the latter has not been thoroughly tested yet).

Structure of a JS project

A simple JS Maven project structure looks like this:

 | +-main
 |  +-js

As you can see we use a structure quite similar to the one used in a Maven based Java project. The main difference is the source directory name ("js" instead of "java") in the same location (${baseDir}/src/main).

Sample POM

Here's a minimal POM for the above project structure:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  <name>My Super JS Library</name>
    <!-- tell Maven to package you JS files as resources -->
        <!-- true or false depending on your taste :-) -->
        <!-- Use maven-jstools-plugin for your reports! -->

This will create JS JAR artifacts. Suppose you have a gr/abiss/js/superlib package (directory) structure under src/main/js, the resulting JAR file will have the following structure:

 /my-super-js-lib-1.0b.jar (the archive itself)

For a more complete example of a JS project POM, you can always check out Sarissa 's POM here .

JavascriptDependencyFilter: Fetching packaged JS resources at runtime

All well and simple up to now, the question is: suppose you use such a JAR as a dependency in your WAR project, how will it work at runtime? Easy: just add maven-jstools-plugin as a normal dependency in your WAR POM and JavascriptDependencyFilter in your webapp config (i.e. web.xml) to intercept requests for JS files or other static resources packaged in your JS-based dependencies. That javadoc link has all the details :-)