I have some JavaScript and CSS files which are not part of my WAR module source repository. They are not packaged in a Maven dependency either. I separately extract them to a path on my local system.
How can I use include these resources in my Maven WAR application and still take advantage of liberty dev mode for rapid, iterative development?
To include web resources from locations other than the typical src/main/webapp directory, configure a property and the maven-war-plugin with the <webResources>
parameter with something like this:
...
<properties>
<webResDir>/path/to/js-css</webResDir>
<properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<webResources>
<resource>
<directory>${webResDir}</directory>
</resource>
</webResources>
<!-- I recommend this config which does a better job of removing any deleted/outdated resources, as of v3.3.2 -->
<outdatedCheckPath>/</outdatedCheckPath>
</configuration>
</plugin>
While the basic idea still applies at earlier versions, you'll get a better experience with recommended minimum versions:
Note too the maven-war-plugin configuration should be added at the plugin level for liberty dev mode to access it, rather than at the level of an execution defined under the maven-war-plugin.
As with Maven project properties in general, this can now be overridden:
mvn -DwebResDir=/some/path ... <goals, phases>
More examples here: https://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html