Building your Front End with Maven: Simple Resources
May 15, 2017 - 4:30pm
Serving up Static Resources
It is assumed that you are already able to serve up static resources from your web application. Generally, whichever framework you are using to build your application has standard ways of supporting this - Spring, for example - uses the mvc:resources tag. Additionally, assuming you are using a Servlet Container such as Tomcat, it is often the case that you can serve anything up that appears in the src/main/webapp directory without any extra configuration at all. It is important that you know where in the resulting WAR file your static files need to end up, as this will be used repeatedly throughout the examples given in this article.
Plain, Unmanipulated Files
The absolute simplest form of static resources that can be included are ones that require absolutely no manipulation. These are files that you write and are then included into the webapp as-is. Including these is really simple. All you need to do is put the files into either src/main/webapp or src/main/resources as appropriate for where you want them to appear. Files included in src/main/webapp will be copied into the root of your WAR file, whereas files included in src/main/resources will be copied into target/classes, which then ends up on the classpath of your webapp.
Sometimes you find that you want to have some plain files, but include in them expanded properties taken from the Maven build. For example, the version number of the artifact is a common one that might be included.
This is achievable using standard Maven plugins that are already used as part of your build - the Maven Resources Plugin and the Maven WAR Plugin - so let's have a look at them.
Maven Resources Plugin
Without any additional configuration at all, the Maven Resources Plugin is already used to copy the src/main/resources directory into
Continue reading this article »