无法安装 Eclipse - 在 Mac 上“无法创建 Java 虚拟机”

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

Can't install Eclipse - "Failed to create the Java Virtual Machine" on Mac

javaeclipse

提问by Brad Parks

I'm trying to install Eclipse, but I can't get the installer to start. It fails with

我正在尝试安装 Eclipse,但无法启动安装程序。它失败了

"Failed to create the Java Virtual Machine"

“未能创建 Java 虚拟机”

How can I resolve this?

我该如何解决这个问题?

Note: I'm on Mac.

注意:我在 Mac 上。

采纳答案by Brad Parks

For me, I had to edit the eclipse-inst.inifile located here:

对我来说,我必须编辑eclipse-inst.ini位于此处的文件:

Eclipse Installer.app/Contents/Eclipse/eclipse-inst.ini

and add the path to my local java VM, which is here:

并将路径添加到我的本地 java VM,它在这里:

-vm
/Users/bparks/jdk/jdk1.8.0_162_x64/bin/java

If the Eclipse Installer.appfile is in a DMG, right click on it, and copy it, then paste it into another folder. Then right click on that app file, and choose "Show Package Contents", to get into the files inside the application.

如果Eclipse Installer.app文件在 DMG 中,请右键单击它并复制它,然后将其粘贴到另一个文件夹中。然后右键单击该应用程序文件,并选择“显示包内容”,以进入应用程序内的文件。

If you've already got Eclipse installed, and find it's throwing the same error, you could try a similar approach by editing the following file for Eclipse:

如果您已经安装了 Eclipse,并发现它抛出相同的错误,您可以通过为 Eclipse 编辑以下文件来尝试类似的方法:

/Applications/Eclipse.app/Contents/Eclipse/eclipse.ini

On mac, you can get the full path you'd need to your java exe by running the following in a terminal, which will copy the path to your clipboard.

在 Mac 上,您可以通过在终端中运行以下命令来获取 Java exe 所需的完整路径,这会将路径复制到剪贴板。

$ echo $(/usr/libexec/java_home)/bin/java | pbcopy

回答by Juan Ignacio Barisich

Edit the file /Applications/Eclipse.app/Contents/Info.plist

编辑文件 /Applications/Eclipse.app/Contents/Info.plist

There is a comment for use a particular JVM:

有使用特定 JVM 的注释:

<key>Eclipse</key>
<array>
    <!-- to use a specific Java version (instead of the platform's default) uncomment one of the following options,
        or add a VM found via $/usr/libexec/java_home -V -->
    <string>-vm</string><string>/Library/Java/JavaVirtualMachines/jdk8u192-b12/Contents/Home/jre/</string>
    <string>-keyring</string>
    <string>~/.eclipse_keyring</string>
</array>

回答by clarkttfu

I met this problem with eclipse-java-2020-03-M2-macosx-cocoa-x86_64, and opendjdk11. The latest eclipse installer at the moment also complained same error.

我遇到了这个问题eclipse-java-2020-03-M2-macosx-cocoa-x86_64,和opendjdk11。目前最新的 eclipse 安装程序也抱怨同样的错误。

After I switched back to openjdk8, everything goes well...

切换回openjdk8 后,一切顺利...

回答by Prashant Basnet

delete all java folder inside /Library/Java

删除 /Library/Java 中的所有 java 文件夹

then install a new jdk from https://adoptopenjdk.net/

然后从https://adoptopenjdk.net/安装一个新的 jdk

which will install at /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk

它将安装在 /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk

then try reinstalling eclipse a

然后尝试重新安装 eclipse a

回答by André Kuhlmann

It took me some time to figure this out as well. The main takeaway was eclipse does not support SDK Version 14(as of eclipse 2020-03). That was not completely obvious to me.

我也花了一些时间来弄清楚这一点。主要的收获是eclipse 不支持 SDK 版本 14(从 eclipse 2020-03 开始​​)。这对我来说并不完全明显。

  1. Install a supported version (I used Homebrew to install SDK V8 ):

    brew cask install adoptopenjdk/openjdk/adoptopenjdk8
    

    If this is the only Java Version you have installed you should be fine and Eclipse should open up. If that is not the case and you have another Java Version installed. You have to tell Eclipse which Version of Java it should be using (see Step 2).

  2. Tell Eclipse which Version to use by editing the /Applications/Eclipse.app/Contents/Info.plistfile as described by Juan Ignacio Barisichand Brad Parks. That being the version you installed in step 1.

    nano /Applications/Eclipse.app/Contents/Info.plist
    # or
    open /Applications/Eclipse.app/Contents/Info.plist
    
    <key>Eclipse</key>
    <array>
        <string>-keyring</string>
        <string>~/.eclipse_keyring</string>
        <string>-vm</string>
        <string>/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/</string>
    </array>
    
  1. 安装支持的版本(我使用 Homebrew 安装 SDK V8 ):

    brew cask install adoptopenjdk/openjdk/adoptopenjdk8
    

    如果这是您安装的唯一 Java 版本,您应该没问题,Eclipse 应该会打开。如果不是这种情况并且您安装了另一个 Java 版本。您必须告诉 Eclipse 它应该使用哪个版本的 Java(请参阅步骤 2)。

  2. /Applications/Eclipse.app/Contents/Info.plist按照Juan Ignacio BarisichBrad Parks 的描述,通过编辑文件来告诉 Eclipse 使用哪个版本。那是您在步骤 1 中安装的版本

    nano /Applications/Eclipse.app/Contents/Info.plist
    # or
    open /Applications/Eclipse.app/Contents/Info.plist
    
    <key>Eclipse</key>
    <array>
        <string>-keyring</string>
        <string>~/.eclipse_keyring</string>
        <string>-vm</string>
        <string>/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/</string>
    </array>
    

Disclaimer:Please bare in mind that those were the steps I took to get eclipse running again. Because I'm nowhere qualified to give a precise answer about this please take a look at the comments in case I got something wrong.

免责声明:请记住,这些是我让 eclipse 再次运行所采取的步骤。因为我没有资格就此给出准确的答案,请查看评论,以防我出错。

Edit:See Christian Friesanswer who pointed out that all java versions 8 to 13 are supported by eclipse.

编辑:请参阅Christian Fries 的回答,他指出 Eclipse 支持所有 Java 版本 8 到 13。

回答by Christian Fries

Note: The error "Failed to create the Java Virtual Machine" also exists with Eclipse 2020-03(under some situations, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=561273) and it is not required to use Java 8 (with Eclipse 2020-03).

注意Eclipse 2020-03 中也存在错误“ Failed to create the Java Virtual Machine” (在某些情况下,请参阅https://bugs.eclipse.org/bugs/show_bug.cgi?id=561273),但不是需要使用 Java 8(使用 Eclipse 2020-03)。

For the impatient:

对于不耐烦的人:

You can run Eclipse or the Eclipse Installer with a given VM without changing eclipse.iniby starting it via a command line:

您可以使用给定的 VM 运行 Eclipse 或 Eclipse 安装程序,而无需eclipse.ini通过命令行启动它:

  • Open Terminal an run:

  • open PATHTOECLIPSEINSTALLER/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/NAMEOFJDK/Contents/Home/bin

  • 打开终端运行:

  • open PATHTOECLIPSEINSTALLER/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/NAMEOFJDK/Contents/Home/bin

where PATHTOECLIPSEINSTALLERis the path of the folder where Eclipse Installer is located and NAMEOFJDKis the name of the folder with the JDK (11, 12, 13).

其中PATHTOECLIPSEINSTALLER是Eclipse Installer所在文件夹的路径,是NAMEOFJDKJDK所在文件夹的名称(11、12、13)。

For example:

例如:

open Downloads/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin

open Downloads/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/bin

In the installer you may select the VM used by Eclipse. Use a compatible VM here and the installer will modify the eclipse.inifor you.

在安装程序中,您可以选择 Eclipse 使用的 VM。在此处使用兼容的 VM,安装程序将为eclipse.ini您修改。

Explanation TL;DR

解释 TL;DR

To clarify this issue:

为了澄清这个问题:

Eclipse - say Eclipse 2020-03 - runs with Java 11, Java 12, Java 13, but does not run with Java 14. It fails with the message "Failed to create the Java Virtual Machine". This happens for the installer and for Eclipse itself.

Eclipse - 比如说 Eclipse 2020-03 - 使用 Java 11、Java 12、Java 13 运行,但不使用 Java 14 运行。它失败并显示消息“无法创建 Java 虚拟机”。安装程序和 Eclipse 本身都会发生这种情况。

You can download Eclipse without the installer from here: https://www.eclipse.org/downloads/packages/

您可以从这里下载没有安装程序的 Eclipse:https: //www.eclipse.org/downloads/packages/

Explanation:

解释:

On macOS, if you start a freshly installed Eclipse, it will use the default JVM. The default JVM is obtained by running /usr/libexec/java_home.

在 macOS 上,如果您启动新安装的 Eclipse,它将使用默认的 JVM。默认的 JVM 是通过运行获得的/usr/libexec/java_home

This program /usr/libexec/java_homewill find the installed JDK with the highest version as default. That is, if you have JDK 14 installed and run Eclipse 2020-03, you will see this error.

该程序/usr/libexec/java_home会默认查找已安装的版本最高的JDK。也就是说,如果您安装了 JDK 14 并运行 Eclipse 2020-03,您将看到此错误。

Solution

解决方案

Summarising some other answers here, there are three options:

在这里总结一些其他答案,有三个选项:

  1. Once you have removed JDK 14 from /Library/Java/JavaVirtualMachines/ the error will be gone.

  2. If you like to have JDK 14 installed, start the installer with a different JDK via the command line open Path-to-Eclipse-Installer/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/NAMEOFJDK/Contents/Home/bin

  3. You may edit the eclipse.ini (as suggested in other answers) to use a specific JVM.

  1. 从 /Library/Java/JavaVirtualMachines/ 中删除 JDK 14 后,错误将消失。

  2. 如果您想安装 JDK 14,请通过命令行使用不同的 JDK 启动安装程序 open Path-to-Eclipse-Installer/Eclipse\ Installer.app --args -vm /Library/Java/JavaVirtualMachines/NAMEOFJDK/Contents/Home/bin

  3. 您可以编辑 eclipse.ini (如其他答案中所建议)以使用特定的 JVM。

回答by Axel Deleye

Referring to Marseille Joseph https://www.eclipse.org/forums/index.php?t=msg&th=1102885&goto=1823113&#msg_num_13This worked for me!

参考马赛约瑟夫 https://www.eclipse.org/forums/index.php?t=msg&th=1102885&goto=1823113&#msg_num_13这对我有用!

Their solution didn't require uninstalling jdk14 or to editing the eclipse.ini file. Instead, do this:

他们的解决方案不需要卸载 jdk14 或编辑 eclipse.ini 文件。相反,请执行以下操作:

cd /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/MacOS/
sudo rm /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/MacOS/libjli.dylib
sudo ln -s /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home/lib/libjli.dylib libjli.dylib

回答by camilablnpa

I had the same problem in my mac. Here is my solution.

我在我的 mac 上遇到了同样的问题。这是我的解决方案。

First: I've uninstall all the versions of jdk, because I've try a lot of options. To do this, you need to go to Library/Java/JavaVirtualMachines and delete all the folders.

第一:我已经卸载了所有版本的jdk,因为我已经尝试了很多选择。为此,您需要转到 Library/Java/JavaVirtualMachines 并删除所有文件夹。

Second: Install jdk 1.8 here is a link to download this version: jdk 1.8

第二:安装jdk 1.8 这里是下载这个版本的链接: jdk 1.8

Third: Install eclipse 2020-03and thats all.

第三:安装eclipse 2020-03仅此而已

If you want to use JDK 14, you need to follow this steps:

如果要使用 JDK 14,则需要按照以下步骤操作:

  1. Open eclipse
  2. Go to Help > Install new software
  3. In the Install window copy the following link in Work withhttps://download.eclipse.org/eclipse/updates/4.15-P-builds/
  1. 打开日食
  2. 转到帮助 > 安装新软件
  3. 在“安装”窗口中,复制“使用https://download.eclipse.org/eclipse/updates/4.15-P-builds/”中的以下链接

Install window

安装窗口

  1. Select the third option show in the picture below Option
  2. Then, click "next" and finish the install
  1. 选择下图所示的第三个选项 选项
  2. 然后,单击“下一步”并完成安装

Now you have to change the options, go to Preferences (command + ,) > Java > Compiler and search the version 14. Before this step you need to install jdk 14 (link)Perhaps eclipse would suggest you to change to the correct JREs, for this you need to go to Java > Installed JREs and add the correct version. When you click addyou need to choose he JRE type, in my case I use a MacOS X VM and Standard VM, then you have to choose the directory (/Library/Java/JavaVirtualMachine/jdk-14/Contents/Home and click openyou could give a JRE Name and finisheclipse will be restart and now you can use eclipse with java 14.

现在您必须更改选项,转到 Preferences (command + ,) > Java > Compiler 并搜索 version 14。在此步骤之前您需要安装 jdk 14 ( link)也许 eclipse 会建议您更改为正确的 JRE,为此,您需要转到 Java > Installed JREs 并添加正确的版本。单击添加时,您需要选择 JRE 类型,在我的情况下,我使用 MacOS X VM 和标准 VM,然后您必须选择目录 (/Library/Java/JavaVirtualMachine/jdk-14/Contents/Home,然后单击打开您可以提供 JRE 名称并完成eclipse 将重新启动,现在您可以将 eclipse 与 java 14 一起使用。

enter image description here

在此处输入图片说明

This works for me, I hope you have understood me.

这对我有用,我希望你能理解我。

回答by Maninder Singh

Go to /Library/Java/JavaVirtualMachines

转到 /Library/Java/JavaVirtualMachines

Delete all version except one in use.

删除除正在使用的版本之外的所有版本。