3

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?

4 Answers 4

1

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\""
Sign up to request clarification or add additional context in comments.

2 Comments

This is the right idea. I just edited your answer to remove quotes around the strings in exec.arguments. Apparently it takes the quotes literally?
Actually, exec:java does have exec.args, and it is not all clear what the difference between exec.arguments and exec.args is.
1

I've just found that this problem might also be solved by putting quotes around the whole -Dexec.args value, like so:

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

Comments

0

This is really a bash quoting issue, not Maven issue as such.

To debug it do

echo $CMD

and then cut and paste the result into your command line. Tinker with quotation till it works

Try

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

for starters

Comments

0

Riffing on @Peter Svensson's answer, I suggest:

-Dexec.arguments=$(echo $@ | tr ' ' ',')

Where $@ is the standard bash symbol for arguments provided to the bash script, and the tr command is changing the list from space-delimited to comma-delimited

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.