Maven – Generate a package with external resources

Maven – How to generate a package with external resources

While making a java batch, it’s a common way to generate a working directory structure like the following:

The directories above will contain:

  • conf – external configuration properties
  • lib – the jar libraries, comprensive of the main jar
  • logs – the log files
  • bin – the sh / bat script file within the instructions to run the batch properly

Our source structure folder will be similar:

  • applconf – external configuration properties
  • scripts – the sh / bat script file within the instructions to run the batch properly
  • logs – the log files

Now it’s time to edit pom.xml properly.

pom.xml

The following lines will copy applconf content inside target conf directory

The following lines copy scripts file inside bin directory

The following copy main jar with dependencies inside lib directory:

The following will generate manifest.inf within the main jar package

Finally, the pom.xml declare that directive to build the zipped package are contained inside assembly-app.xml file

assembly-app.xml

These directives will copy jar dependencies inside lib directory and applconf content inside conf directory.

If our need is to place main jar outside lib directory, copy the following lines instead: