Mainly Spring/Java and Java JEE tips and tutorials based on what i'm working on, usually (Spring, MongoDB, Spring boot, Big Data, Cassandra etc.) or what interests me.
Occasionally some gadget tips.
Maven custom packaging with the assembly plugin
It's not uncommon to need a custom packaging or assembly for a given project for some reason or another, this can be accomplished in a certain number of ways
Recently I needed an application to be packaged as the following structure :
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
Your project can build distribution assemblies easily, using one of the convenient, prefabricated assembly descriptors.
These descriptors handle many common operations, such as packaging a project's artifact along with generated documentation into a single ZIP archive. Alternatively, your project can provide its own descriptor and assume a much higher level of control over how dependencies, modules, file-sets, and individual files are packaged in the assembly.
Currently the plugin can create distributions in the following formats:
zip
tar
tar.gz
tar.bz2
jar
dir
war
format that the ArchiveManager has been configured
For this tutorial we will be using the dir format in order to output the project structure described above
Let's start with the easy part first, the maven assembly plugin configuration where we will tell the plugin where to find our assembly file and where to output the result of the assembly operation
Now since in our case we want all the files in the resource directory to be handled by the assembly plugin we will configure the maven resources plugin to ignore everything inside the resources folder (please note that this is an optional step and it might not apply to your project)
...
${basedir}/src/main/resources**/**
...
Once the maven part is done we can get started with the core code
If you remember we will end up with a runnable JAR file so go ahead and create a Main class like so :
package com.ufasoli.maven.custom.assembly;
/**
* User: Ulises Fasoli
* Date: 23.06.2014
* Time: 18:03
* Project : maven-custom-assembly
*/
public class Main {
public static void main(String[] args) {
System.out.println("HELLO WORLD !");
}
}
Since this is going to be a runnable JAR file we will need to configure the maven JAR plugin to generate the manifest file with our main class
No comments:
Post a Comment