java 如何在 Maven 2 exec 插件的参数中使用空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4716643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:41:27  来源:igfitidea点击:

How to use space in arguments for Maven 2 exec plugin

javamaven-2mavenmaven-plugin

提问by mjn

Related Question: Maven Exec Plugin not reading configuration

相关问题:Maven Exec 插件不读取配置

In my configuration I need an argument which is a file path. I found a rather "dirty" workaround by surrounding the argument with quotes in the POM ("dirty" because the argument will be passed to the main method with these quotes, they have to be removed again in the code).

在我的配置中,我需要一个参数,它是一个文件路径。我发现了一个相当“脏”的解决方法,即在 POM 中用引号包围参数(“脏”,因为参数将通过这些引号传递给 main 方法,它们必须在代码中再次删除)。

<configuration>
    <executable>java</executable>
    <arguments>
        <argument>"path to file"</argument>
    </arguments>
</configuration>

However I have found no solution for passing the path as a command line argument:

但是我没有找到将路径作为命令行参数传递的解决方案:

>mvn exec:java -Dexec.args="path to file"

回答by Alexandre DuBreuil

In general, maven requires the whole argument to be quoted if there is space in the argument value.

通常,如果参数值中有空格,maven 需要引用整个参数。

mvn exec:java "-Dexec.args=path to file"

回答by Claude

On the command line, you may try using single-quotes (but I'm not sure if it works), e.g.:

在命令行上,您可以尝试使用单引号(但我不确定它是否有效),例如:

>mvn exec:java -Dexec.args="'path to file' arg2 arg3"

回答by user3227576

Use -Dexec.args="'space parameter' normalparameter 'one more space parameter'"

利用 -Dexec.args="'space parameter' normalparameter 'one more space parameter'"

I've tried it on Windows and it works.

我已经在 Windows 上试过了,它可以工作。

回答by ssedano

If you want it in command line try: $ mvn exec:java -Dexec.args="path\ to\ file arg2 arg3"

如果你想在命令行中尝试: $ mvn exec:java -Dexec.args="path\ to\ file arg2 arg3"

回答by Sandeep

Try -Dexec.arguments="path to file"(instead of -Dexec.args="path to file")

尝试-Dexec.arguments="path to file"(而不是-Dexec.args="path to file"

Check here for details.

请在此处查看详细信息。