I would like to generate multiple WAR files, during the build cycle of my project. I already know how to add multiple dest-file, and other configuration with the maven-war-plugin. But I want to know if there is way to generate an indeterminate number of war during the build cycle, without writing configuration for each WAR.
I want to generate a build for each clients, I have the following directory structure in my project:
| pom.xml
+ src
+ main
+ clients
+ client1
+ client2
+ client3
+ ...
+ clientn
I would like to know how to generate a WAR for each client directory. I just want to create a Maven configuration, then just care about adding a new folder then mvn package
and get n WAR packages.
Is it possible?
Seems like Maven cannot do that by itself, so I ended up creating a script that invoke Maven for each folder found in src/main/clients
.
#!/bin/bash
clear
###
# Check for Apache Maven home environment variable.
###
M2_HOME=`$M2_HOME`
if [ -z "$M2_HOME" ]; then
echo "Error: M2_HOME variable not set. Please set Apache Maven home."
exit
fi
###
# Build all client packages.
###
echo "Build start."
for f in $0/src/main/clients/*
do echo Building: %f
$M2_HOME/bin/mvn package -Dclient.id=`basename $f` -Dclient.path=$f -DskipTests
done;
echo "Build end."
@ECHO off
SET M2_HOME=%M2_HOME%
CD %~p0
ECHO Build start.
FOR /r /d %%G in (src\main\client\*) DO (
ECHO Building: %%~nG
%M2_HOME%\bin\mvn package -Dclient.id=%%~nG -Dclient.path=%%G -DskipTests
)
ECHO Build end.