We’re using the Maven exec:java goal to run a custom java application that configures a database for use with our integration tests. We want to use exec:java over exec:exec to be able to use the project dependencies in the classpath of the main class to be used.
A few times the application has failed for valid reasons, but the Maven build continued as if nothing had gone wrong.
Is there any “failonerror” type argument that can be used with exec:java? I’m afraid to add system.exit() codes to the class being run, as I suspect it will kill not only itself, but also Maven itself, due to the fact it’s running in the Maven VM.
I just did a simple test with the following plugin configuration declared in a POM:
And the following Java class:
And this is what I get when invoking the
integration-testphase:$ mvn clean integration-test [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building q2363055 [INFO] task-segment: [clean, integration-test] [INFO] ------------------------------------------------------------------------ ... [INFO] [jar:jar {execution: default-jar}] [INFO] Building jar: /home/pascal/Projects/stackoverflow/q2363055/target/q2363055-1.0-SNAPSHOT.jar [INFO] Preparing exec:java [WARNING] Removing: java from forked lifecycle, to prevent recursive invocation. [INFO] No goals needed for project - skipping [INFO] [exec:java {execution: my-exec-java}] [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] An exception occured while executing the Java class. null A problem occured [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: 19 seconds [INFO] Finished at: Tue Mar 02 23:40:32 CET 2010 [INFO] Final Memory: 16M/79M [INFO] ------------------------------------------------------------------------The
integrationphase is never executed, because of the build error.So the question is, how are you handling errors in the Java class that loads your db? Is throwing an exception an option?