使用 Maven 的 Java 不会构建:无法运行程序“cmd”“格式错误的参数已嵌入引号”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58411279/
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-08-11 01:19:38  来源:igfitidea点击:

Java with maven wouldn't build: Cannot run program "cmd" "Malformed argument has embedded quote"

javawindowsmavennetbeans-11

提问by busyBee

I've a fresh install of netbean 11.1. Now I'm trying to build a project but I get the following error output:

我全新安装了 netbean 11.1。现在我正在尝试构建一个项目,但出现以下错误输出:

Cannot run program "cmd" (in directory "C:\projects\open"): Malformed argument has embedded quote: "C:\Program Files\NetBeans-11.1\netbeans\java\maven\bin\mvn.cmd"

无法运行程序“cmd”(在目录“C:\projects\open”中):格式错误的参数已嵌入引号:“C:\Program Files\NetBeans-11.1\netbeans\java\maven\bin\mvn.cmd”

cd C:\projects\open; "JAVA_HOME=C:\Program Files\Java\jdk-11.0.5" cmd /c "\"\"C:\Program Files\NetBeans-11.1\netbeans\java\maven\bin\mvn.cmd\" -DskipTests=true -Dmaven.ext.class.path=\"C:\Program Files\NetBeans-11.1\netbeans\java\maven-nblib\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\"" Cannot run program "cmd" (in directory "C:\projects\open"): Malformed argument has embedded quote: "C:\Program Files\NetBeans-11.1\netbeans\java\maven\bin\mvn.cmd" -DskipTests=true -Dmaven.ext.class.path="C:\Program Files\NetBeans-11.1\netbeans\java\maven-nblib\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 clean install

I've build this project with netbeans 11.1 before but have a new pc. and a fresh install, tho I'm sure there was no problem last time I tried to install everything.

我以前用 netbeans 11.1 构建过这个项目,但有一台新电脑。和全新安装,但我确定上次尝试安装所有内容时没有问题。

采纳答案by Ali Safari

Although this problem can be fixed by installing jdk1.8.0_221, but actually you don't need to downgrade your JDK. Just try these:

虽然这个问题可以通过安装jdk1.8.0_221来解决,但实际上你不需要降级你的JDK。试试这些:

  1. First exit netbeans IDE if it's open, then open netbeans configuration file from here: netbeans-Install-Dir/etc/netbeans.conf (Note: for me netbeans-Install-Dir is C:\Program Files\NetBeans 8.2\etc)
  2. Add the below arguments
  1. 首先退出 netbeans IDE,如果它打开,然后从这里打开 netbeans 配置文件:netbeans-Install-Dir/etc/netbeans.conf(注意:对我来说 netbeans-Install-Dir 是 C:\Program Files\NetBeans 8.2\etc)
  2. 添加以下参数
-J-Djdk.lang.Process.allowAmbiguousCommands=true
  1. to the beginning of the string that you find at this line:
  1. 到您在这一行找到的字符串的开头:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m ......."

Sample screenshot as shown below: enter image description here
4. Save the change and start your netbeans IDE.

示例屏幕截图如下所示: 4. 保存更改并启动您的 netbeans IDE。在此处输入图片说明

回答by angusg96

Did you by any chance install the latest critical update for java? jdk 1.7_241? I installed that today and was having the exact same problem. I downgraded my jdk version and it solved it completely.

您是否有机会安装最新的 Java 关键更新?jdk 1.7_241?我今天安装了它并且遇到了完全相同的问题。我降级了我的 jdk 版本,它完全解决了它。

EDIT: Apologies, I noticed you're using netbeans 11.1 so you probably have a later java version, in any case, you could try downgrading your java version to a previous release if you happened to update it today as the other version might have the same problem.

编辑:抱歉,我注意到您使用的是 netbeans 11.1,所以您可能有更高的 Java 版本,无论如何,如果您今天碰巧更新它,您可以尝试将 Java 版本降级到以前的版本,因为另一个版本可能有同样的问题。

回答by marcello

At the time that I'm writing, I had only JDK13 installed only on my machine. After unzipped my netbeans I've got the same problem with the internal maven of my netbeans 11.1.

在我写这篇文章的时候,我只在我的机器上安装了 JDK13。解压缩我的 netbeans 后,我的 netbeans 11.1 的内部 maven 遇到了同样的问题。

Apparently netbeans 11.1 does not work properly with the JDK13. I just installed the JDK 8 and the problem now is solved, without any additional configuration or parameter change.

显然,netbeans 11.1 不能与 JDK13 一起正常工作。我刚刚安装了JDK 8,现在问题解决了,没有任何额外的配置或参数更改。

Nontheless, since I need the JDK13, I have both installed but my netbeans.conf file is pointing to JDK8. Later, you can define the new Java platform in netbeans project configuration.

尽管如此,因为我需要 JDK13,所以我都安装了,但我的 netbeans.conf 文件指向 JDK8。稍后,您可以在 netbeans 项目配置中定义新的 Java 平台。

I hope this might help.

我希望这可能会有所帮助。

Cheers!

干杯!

回答by Geertjan Wielenga

Apache NetBeans 11.1 does indeed not support JDK 13, that's what the upcoming Apache NetBeans 11.2 is for -- latest beta: bit.ly/apache-netbeans-11-2-beta-3

Apache NetBeans 11.1 确实不支持 JDK 13,这就是即将推出的 Apache NetBeans 11.2 的用途 -- 最新测试版:bit.ly/apache-netbeans-11-2-beta-3

回答by Pierre Maréchal

It seems to happen with all recently released jdk version (11.0.5 and 13.0.1 at least), even with the latest Netbeans 11.2vc1 (and witnessed on NB 11.1 too). Downgrade your jdk to 11.0.4 or 13.0.0. It fixed the issue for me

所有最近发布的 jdk 版本(至少 11.0.5 和 13.0.1)似乎都会发生这种情况,即使是最新的 Netbeans 11.2vc1(也在 NB 11.1 上见证)。将您的 jdk 降级到 11.0.4 或 13.0.0。它为我解决了这个问题

回答by govojo

I had the same problem with oracle jdk 13.0.1 and netbeans 11.1, but it worked for me with openjdk 13.0.1 (https://jdk.java.net/13/).

我在使用 oracle jdk 13.0.1 和 netbeans 11.1 时遇到了同样的问题,但它在使用 openjdk 13.0.1 ( https://jdk.java.net/13/) 时对我有用。

回答by Felipe Moreira Jorge

The problem also occurs in version jdk-8u231. Fixing installing jdk-8u221 version

jdk-8u231 版本也会出现这个问题。修复安装 jdk-8u221 版本

回答by Sephiroth

I have checked the release notes for JDK 13.0.1 at https://www.oracle.com/technetwork/java/javase/13-0-1-relnotes-5592797.html#JDK-8221858

我已经在https://www.oracle.com/technetwork/java/javase/13-0-1-relnotes-5592797.html#JDK-8221858查看了 JDK 13.0.1 的发行说明

This behavior is a regression from a security fix for JDK-8221858 (not public). Follow the link for a full description. The fix is part of JDK 8u231, JDk 11.0.5, 13.0.1 etc.

此行为是对 JDK-8221858(非公开)的安全修复的回归。点击链接获取完整说明。该修复是 JDK 8u231、JDK 11.0.5、13.0.1 等的一部分。

To resolve this problem, append -J-Djdk.lang.Process.allowAmbiguousCommands=trueto netbeans_default_optionsin <netbeans-dir>\etc\netbeans.conf.

要解决此问题,请附加-J-Djdk.lang.Process.allowAmbiguousCommands=truenetbeans_default_optionsin <netbeans-dir>\etc\netbeans.conf

回答by raisercostin

I had this error with adopt8-hotspot (AdoptOpenJDK-1.8.0_232-b09)and sbt-0.13.Xfor an old project.

我有这个误差adopt8-hotspot (AdoptOpenJDK-1.8.0_232-b09)sbt-0.13.X一个旧的项目。

Problem solved after setting the environment variable in windows via

通过在windows中设置环境变量后问题解决

set JAVA_TOOL_OPTIONS=-Djdk.lang.Process.allowAmbiguousCommands=true

回答by Ahmad Haj Abdulla

just add -J-Djdk.lang.Process.allowAmbiguousCommands=true to netbeans_default_options in netbeans.conf

只需将 -J-Djdk.lang.Process.allowAmbiguousCommands=true 添加到 netbeans.conf 中的 netbeans_default_options