Skip to content
Advertisement

Using Maven Exec Plugin inside Bash

I’m writing a bash script which will execute some part of a maven project. The script looks like this:

CMD="mvn exec:java -Dexec.mainClass=$MAINCLASS -Dexec.args="cfg.txt TRAIN""  
echo "Running $CMD..."

$CMD

But this fails every time with the following error:

[ERROR] Unknown lifecycle phase "TRAIN". You must specify a valid 
lifecycle phase...

If I skip the CMD=... assignment, and just run the mvn part directly, like this…

mvn exec:java -Dexec.mainClass=$MAINCLASS -Dexec.args="cfg.txt TRAIN"

…it works just fine.

How can I get maven and the exec plugin to understand that I have two arguments in the -Dexec.args section?

Advertisement

Answer

According to the docs exec:java has no exec.args? It does have exec.arguments which takes a String[] which would translate into:

CMD="mvn exec:java -Dexec.mainClass=$MAINCLASS -Dexec.arguments="cfg.txt","TRAIN""
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement