0

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.

Pete Carter
  • 2,691
  • 3
  • 23
  • 34
J.E.Y
  • 1,173
  • 2
  • 15
  • 37

1 Answers1

0

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!

Stephen Connolly
  • 13,872
  • 6
  • 41
  • 63
  • hi Steve. Thanks for the detialed explaination. It works per your suggestion. THen why is the use for in the first place? – J.E.Y Oct 22 '12 at 13:52
  • maybe the Main you are invoking chains onto the real main (rather than exiting when finished) and you need to pass the real main classname. Or maybe you have to set some options, etc. Flexibility is a good thing, and convention over configuration means you don't have to configure things until you need them – Stephen Connolly Oct 22 '12 at 13:57
  • What version of appassembler plugin do you use? I'm asking because in version 1.3 it's not possible to pass params through the script to Main class. – shinydev Jan 23 '13 at 12:05