Quoting and speeding up in Maven Exec plugin

How do quotes and escaping work for parameters passed to Maven plugins?

For example, I want to pass multiple filenames as arguments to an application launched by the Maven Exec plugin:

mvnDebug exec:java -Dexec.mainClass="Main" -Dexec.args="/path/to/file1 /path/to/file2"

But what if the paths have spaces?

I've tried using \ ":
-Dexec.args="\"/path/to/a file\" /path/to/file2"

and "":
-Dexec.args="""/path/to/a file"" /path/to/file2"

doesn't work :-(. Also doesn't move the first quote before -D.

The source code for the Maven Exec plugin doesn't help me either, it gets the [] string from somewhere, but where?

Please note that I have to get this to work from the command line with no changes to the POM file.


source to share

1 answer

You can try single quotes ( '

), but I doubt it will work.

The problem is that there can be multiple elements inside the POM argument

(hence the array in the plugin source), but from the command line, you only have one property.


  • Run the plugin and / or open a function request to support multiple arguments (maybe exec.args.0, exec.args.1, exec.args.2, ...


  • Create a module that depends on that project / module and where you can change the POM

  • Use Ant or BASH script. I often use this approach to collect useful commands that Maven does not easily support. mvn dependency:build-classpath -Dmdep.outputFile=...

    will give you the classpath in this case.



All Articles