use of the tag <commandLineArguments> in the maven plugin appassembler

1.3k views Asked by At

I am using the maven plugin appassembler to generate a unix script. In its tag, I put sth like:

<commandLineArguments>
  <commandLineArgument>$1</commandLineArgument>
  <commandLineArgument>$2</commandLineArgument>
  <commandLineArgument>$3</commandLineArgument>
</commandLineArguments>

The resultant script, however, shows $1 $2 $3 "$@"

I don't know where the last one came from, it therefore repeat the first 3 arguments.

1

There are 1 answers

3
Stephen Connolly On

Mojo's AppAssembler Maven Plugin generates a script that always appends all the command line arguments provided to the script onto the JVM's launch command. Thus if you did nothing, the "$@" will be the last thing on the JVM command used to start the program.

The <commandLineArguments> tag is used to inject additional command line arguments before the ARGLIST matcher.

It seems (to me) that you think you needed to add the positional markers in order to get the parameters passed through, hence the snippet you were adding. That is both:

  1. Unnecessary, as by default the plugin generates a script that passes all required parameters.
  2. Actually a potential bug, as what you have configured does not handle argument quoting and escaping correctly.

With regard to the second point consider the case where the second parameter is the name of a file that contains a space charater. If I launch the script for you program like so

$ bin/foo.sh Document.txt Document\ 2.txt "Copy of Document 3.txt" Doc4.txt

you will actually see the following being passed through to your Java program with the configuration you provided:

  1. Document.txt (all of $1)
  2. Document ($2 is expanded, but not quoted so now gets re-evaluated)
  3. 2.txt
  4. Copy ($3 is expanded, but not quoted, so also gets re-evaluated, spaces seen as argument separator again)
  5. of
  6. Document
  7. 3.txt
  8. Document.txt (now the ARGLIST matcher provides everything correctly)
  9. Document 2.txt
  10. Copy of Document 3.txt
  11. Doc4.txt

The solution is simple. Stop trying to configure something you don't need to configure!