Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

eclipse

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

"Failed to create the Java Virtual Machine"

How can I resolve this?

Note: I'm on Mac.

like image 572
Brad Parks Avatar asked Oct 04 '18 18:10

Brad Parks


People also ask

How do I fix a failed Java VM?

If you have the correct JRE installed and you still get a "Failed to find Java VM" message, please try reinstalling Java – if Charles can't find your JRE then it is likely that your registry contains some invalid details, which reinstalling will correct.

Is Eclipse compatible with Mac?

The Eclipse Installer 2022‑06 R now includes a JRE for macOS, Windows and Linux.


4 Answers

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

There is a comment for use a particular 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>
like image 60
Juan Ignacio Barisich Avatar answered Oct 18 '22 04:10

Juan Ignacio Barisich


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.

  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.plist file as described by Juan Ignacio Barisich and 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>
    

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.

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

like image 31
André Kuhlmann Avatar answered Oct 18 '22 02:10

André Kuhlmann


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

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

and add the path to my local java VM at the very top of the .ini file, which is here:

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

If the Eclipse Installer.app file 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.

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:

/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.

$ echo $(/usr/libexec/java_home)/bin/java | pbcopy
like image 15
Brad Parks Avatar answered Oct 18 '22 03:10

Brad Parks


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).

For the impatient:

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

  • Open Terminal an run:

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

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

For example:

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.ini for you.

Explanation 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.

You can download Eclipse without the installer from here: 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.

This program /usr/libexec/java_home will 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.

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.

like image 11
Christian Fries Avatar answered Oct 18 '22 02:10

Christian Fries