Using maven-exec-plugin
and a java goal I execute a jar program that validates some files in my project. When the validation fails, it calls System.exit
to return a non zero return code.
The problem is that it executes in the same JVM as Maven, so when it calls exit, the processing stops since it does not fork.
I configured it to execute with maven-exec-plugin
and a java goal (like in here ). The execute jar is in my Nexus repository, so I want to download it as a dependency in my pom.xml.
A very nice feature of configuring the maven-exec-plugin dependency is that it downloads the jar and all its dependencies, so it isn't necessary to use maven assembly plugin to include all jars in the executable.
How do I configure my pom.xml to execute a jar dependency and correctly stop when it fails?
I solved my problem. Basically, instead of using the
java
goal, I must use theexec
goal, and run the java executable. The code below sets the classpath and the class with the main method.This solution using the pom.xml and a Nexus repository has a lot of advantages over just handling a jar file for my users:
Here is a commented
pom.xml
:You can run more than one executable passing its id:
mvn exec:exec@MyValidator