Software Development

Add external resource directories to jar using build-helper-maven-plugin

This post demonstrates how to add directories that contain resources needed by an application using build-helper-maven-plugin via Maven.

Simple Cases

In simple cases, resources like .properties and XSDs go with project codes. Consider the following Maven project that builds a codebase into an executable jar file.

When we mvn clean package our application, we’ll have the following contents of the jar file. Those clients-config-* directories become readily available to codes that come along with the jar file.

External Resource Directories

In this section, we try to externalize the clients-config-* resource directories. First, we move them to some external directory or directory that will not be read from during the build process.

If we mvn clean package our application without changing anything else, the content of our jar file is as follows.

Using build-helper-maven-plugin plugin

To include all clients-config-* directory from somewhere-external, we need to use a Maven plugin – build-helper-maven-plugin. This requires modifying our pom.xml to

Package again using

and we will get the following content for the jar file.

Download the codes


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like