46

I'm trying to get the new 1.7 JDK working with Eclipse (this is Oracle's official release).

I don't mean just pointing Eclipse to it so you can use it in projects, this works fine, but actually making Eclipse run using the 1.7 JVM.

I've moved the new JVM to the top of the list in Java Preferences, but Eclipse still starts with 1.6. If I disable 1.6 in Java Preferences I get a dialog immediately after I double-click on Eclipse saying "Failed to create the Java Virtual Machine".

edit: I added the following to my eclipse.ini just before the -vmargs:

-vm
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home/bin/java

Yet in the Eclipse installation details dialog I still see:

java.runtime.version=1.6.0_31-b04-415-11M3646

edit 2: here are the contents of my eclipse.ini file: https://gist.github.com/2512578

sanity
  • 35,347
  • 40
  • 135
  • 226
  • Is that a path to the actual java executable or a directory? It has to link to the actual executable to work. Also, what version of Eclipse are you using? – Haz Apr 27 '12 at 16:18
  • It's the actual executable. I'm using Indigo Service Release 2 Build id: 20120216-1857 – sanity Apr 27 '12 at 18:48
  • Could you post the full contents of your eclipse.ini file? – Haz Apr 27 '12 at 20:12
  • @haz sure, just added it to the question – sanity Apr 27 '12 at 20:16
  • 1
    This is very strange. If the -vm argument is specified, I believe that should overrule any other JVMs that Eclipse would otherwise use. Is there a JVM installed in the jre directory under the eclipse directory? Perhaps for whatever reason, the specific version of Eclipse you are using will pick up that JVM over the one specified in eclipse.ini. If that doesn't lead anywhere, I would look at which JVM is pointed to in your path and determine if that's the one Eclipse is using. Obviously changing your system's default JRE isn't the optimal solution here but it's probably worth looking into. – Haz Apr 27 '12 at 22:28
  • 1
    It turns out that the specifications for the Eclipse Launcher explicitly ignore the -vm parameter on a mac. See: http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Flauncher.html At the bottom it says: "MacOSX: The launcher uses the system JavaVM framework and will always load the vm in-process using the JNI invocation API." – Scott Carey Jun 12 '13 at 08:46
  • Oddly enough, Eclipse Kepler announces its requirement of Java 6 when you launch it and won't start without it. However, if Java 7 is installed as well, Eclipse will actually run under a Java 7 JRE and not the Java 6 one claimed by the launcher. :( – Christopher Schultz Oct 24 '13 at 20:05
  • I just fought through this and posted the details [in another question][1]. [1]: http://stackoverflow.com/a/19965368/1550030 – Kevin Clifton Nov 13 '13 at 22:09
  • Make sure you are using 64bit Eclipse. Had no luck running 32bit one on 1.7 jvm with any options. – tuxSlayer Nov 14 '13 at 19:39
  • @ScottCarey - fixed link: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Flauncher.html (helios will redirect to Kepler, which will render the original URI point to an empty location) – orbanbalage Jan 24 '17 at 15:14

14 Answers14

35

There is another way. Please add two following lines before -vmargs in the .ini file:

-vm 
{YOUR_JAVA_7_HOME}/jre/lib/server/libjvm.dylib

(remember these need to be separate lines) and also add a corresponding entry in 'Info.plist' file (add or modify array items under "Eclipse" key - each string child element corresponds to a command line parameter).

...
<key>Eclipse</key>
<array>
<string>-vm</string>
<string>/{MY_VM_HOME}/jre/lib/server/libjvm.dylib</string>
...
</array>

Alternatively just use -vm {YOUR_JAVA_7_HOME}/lib/server/libjvm.dylib command line parameter when running eclipse from terminal.

Anthony
  • 12,407
  • 12
  • 64
  • 88
  • 2
    This worked for me (eclipse 3.7.1), I don't know why it's not marked as the good answer. – Alex Mar 22 '13 at 15:48
  • I confirm that this worked (in eclipse.ini and plist.info) with my Eclipse Indigo install! Thanks. – BoD Oct 13 '13 at 17:11
  • Trying this out on Mavericks and failed. (1) Used /usr/libexec/java_home to determine {JAVA_7_HOME}. It gave /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home. There is a lib subdirectory but no lib/server subdirectory. (2) I find the "add a corresponding entry in 'plist.info' file" a little sparse. The closest equivalent for me is Info.plist (capitalized) in the Contents directory, but not sure what to add there. – bwbecker Nov 07 '13 at 17:10
  • Thanks for the comments. @1 The example was based on JRE. Could you update the path accordingly for JDK which points to libjvm.dylib? @2 yes it's 'Info.plist' I corrected it now and added example change that needs to be done. Thanks again.:) – Jan Arciuchiewicz Nov 11 '13 at 12:40
  • 6
    For Kepler and JRE 1.7 have The JVM shared library "/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/server/libjvm.dylib" does not contain the JNI_CreateJavaVM symbol. – tuxSlayer Nov 14 '13 at 18:44
  • This seems to be recommended way by Oracle according to the comments in Info.plist – ericn Aug 17 '14 at 06:02
  • So amazing, this answer works for me (eclipse indigo) – Lijie Xu Oct 07 '14 at 05:28
31

I just added my comment to https://bugs.eclipse.org/bugs/show_bug.cgi?id=339788 regarding the inability to use the new Oracle JDK with Eclipse on OS X. Using the -vm option inside eclipse.ini does not work. The only way I found to work around this was to use the following shell script:

#!/bin/sh
#
export JAVA_HOME=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
LAUNCHER_JAR=/Applications/eclipse/plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar

java \
-showversion \
-XX:MaxPermSize=256m \
-Xms1024m \
-Xmx1024m \
-Xdock:icon=/Applications/eclipse/Eclipse.app/Contents/Resources/Eclipse.icns \
-XstartOnFirstThread \
-Dorg.eclipse.swt.internal.carbon.smallFonts \
-Dosgi.requiredJavaVersion=1.5 \
-jar $LAUNCHER_JAR

Using the steps on http://mathiasbynens.be/notes/shell-script-mac-apps, I turned the script above into an application that I can keep on my dock.

jkwuc89
  • 1,345
  • 14
  • 20
  • Also, this is interesting : https://bugs.eclipse.org/bugs/show_bug.cgi?id=374792#c3 – Ashutosh Jindal Aug 28 '12 at 19:48
  • 1
    The problem is in the launcher binary of Eclipse 3.7. For Eclipse 3.7.2, that's the file `plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.101.v20120109-1504/eclipse_1408.so` The corresponding `eclipse*.so` from Eclipse 4.x can handle the new Java 7 versions for Mac OS X. Now this is a terrible hack, but if you really need to use a 3.7.x target platform, you can simply copy the newer `eclipse*.so` from an Eclipse 4.3 setup into your product. You do need to keep the original file names, though, so for Eclipse 3.7 is must still use the above plugin name and `eclipse_1408.so`. – Kay Jun 18 '13 at 14:41
  • 1
    Did not work for me, just like the other 3 mentioned solutions. Really, is it this hard to get Eclipse working on OSX Mavericks? even almost half a year after its release? i've started a new thread here: http://stackoverflow.com/questions/22725267/osx-10-9-mavericks-and-eclipse-kepler-4-3-2-or-m6-eclipse-luna-4-4 – Michahell Mar 29 '14 at 00:01
  • @Kay - thank you for the hack, verified, this is exactly the problem and it works by just replacing that library – Dima Apr 12 '16 at 11:16
8

Apparently there is a fix for Kepler that should come out in the next service release.

Meanwhile, there is a workaround that is mentioned in this bug that will allow you to run eclipse without ever installing JRE 1.6 from Apple: https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361#c20

This will allow you to launch eclipse from the finder or spotlight but not the dock.

I've just tested this on OS X Mavericks, which during the update loses jre 6 and asks for it to be installed when you try to launch Eclipse. I have the latest Oracle JDK 1.7 installed of course.

Decline to do that and then to work around this, edit the jvm capabilities in /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Info.plist

<key>JVMCapabilities</key>
            <array>
                    <string>CommandLine</string>
                    <string>JNI</string>
                    <string>BundledApp</string>
                    <string>WebStart</string>
                    <string>Applets</string> 
            </array>

With this fix, you don't need to specify the vm in eclipse.ini.

Jilles van Gurp
  • 7,927
  • 4
  • 38
  • 46
  • This gives me a "failed to create the java virtual machine". P.S. I have JDK 1.7.0_45 installed and working – ksiomelo Dec 25 '13 at 14:39
  • This works fine for me, and seems a little neater than changing Eclipse distro files. However it does require you to reboot your Mac. – Richard Gaywood Jan 28 '14 at 21:18
  • Ah, this is great. After Googeling and trying at least 20 different things, this was the only solution that worked. Thank you so much. Running Mavericks if anyone out there are struggling as well. Note that (as stated above) a reboot is required. – OptimusCrime Feb 09 '14 at 00:05
  • I had a similar problem that could be solved this way, but I also found that adding empty folders at `/System/Library/Java/JavaVirtualMachines/1.6.0.jdk` and `/System/Library/Java/Support/Deploy.bundle` caused OS X to use the Oracle JDK without modification. – Eric3 Jan 11 '15 at 00:13
6

On a Mac above does not seem to work. For me with Eclipse KEPLER it worked by adding

-vm /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/

at the end of my eclipse.ini (without that linebreak)

This finally changed my Eclipse Installation Details > Configuration from

-vm /System/Library/Frameworks/JavaVM.framework

to

-vm /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bin/../jre/lib/server/libjvm.dylib

This did not work with my Eclipse INDIGO installation.

3

After installing Oracle JRE and JDK, open Info.plist inside Eclipse.app(right click, show contents) and paste after "Eclipse" "-vm/System/Library/Frameworks/JavaVM.framework/JavaVM"

Mine looks like this:

    <key>Eclipse</key>
    <array>
        <string>-vm</string><string>/System/Library/Frameworks/JavaVM.framework/JavaVM</string>
        <string>-keyring</string><string>~/.eclipse_keyring</string>
        <string>-showlocation</string>
    </array>

If you do that, you will not have to update the file after upgrading JRE.

adriannieto
  • 352
  • 2
  • 7
  • This is the only solution that worked for me, however I did try a lot of other steps. If you are having problems I would suggest you make sure you have the latest version of Eclipse and the JDK installed and then try this answer. I had installed Java 6 via the standard OS prompt before installing JDK 7, not sure if that helped or hurt. – Hayes Haugen Dec 21 '13 at 18:43
2

Just edit

Eclipse.app/Contents/Info.plist

You have to use a specific Java version (instead of the platform's default) uncomment one of the following options:

<string>-vm</string>
<string>/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java</string>

This helped me rollback from 1.7.0 to 1.6.0.

Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
2

Check your java_home is corrento in /usr/libexec/java_home;

Do not change your eclipse.ini and edit the Info.plist file and change/add this line < string>-vm< /string>< string>/Library/Java/JavaVirtualMachines/'jdk-version-your'/Contents/Home/bin/java< /string> and save. Open Eclipse and done!

For me it worked well, and to use javafx e(fx)clipse!

PS: On a Mac OS X system, you can find Info.plist by right-clicking (or Ctrl+click) on the Eclipse executable in Finder, choose Show Package Contents, and then locate Info.plist in the Contents folder.

Laisson
  • 334
  • 1
  • 2
  • 10
1

Assuming you are using a version of Eclipse which supports Java 7 (I believe anything 3.7 and above) you should be able to specify the JVM used by Eclipse in the eclipse.ini file. If you open it up, you should see a "-vm" property followed by the directory of the JVM you're currently using. You should be able to just change this directory to your 1.7 installation.

Note: I've not used Eclipse on Mac, so the name of the configuration file may be different.

Haz
  • 2,539
  • 1
  • 18
  • 20
  • 3
    The format of `eclipse.ini` is very particular, and finding it in Mac OS X is a little tricky. See http://wiki.eclipse.org/Eclipse.ini – E-Riz Apr 27 '12 at 15:06
  • Thanks for the excellent link. I was not aware of the specific ordering for options in eclipse.ini. – Haz Apr 27 '12 at 15:14
1

As of 2012-04-28, it is a known unresolved bug in Eclipse 3.7 SR2 launcher app.

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=339788

Bruno Laturner
  • 366
  • 3
  • 8
  • As of 2012-07-03, it's marked as a duplicate of [bug 374791](https://bugs.eclipse.org/bugs/show_bug.cgi?id=374791), which is marked as RESOLVED FIXED but still doesn't work for me on Eclipse 4.2 – Daniel Serodio Jul 03 '12 at 19:03
1

I just had this problem. I fixed it by downgrading and downloading JDK 7.

0

I had a similar problem after downloading and installing Titanium. My eclipse worked but Titanium didn't and so I ended up looking in the config file to see what was different

Eclipse had

eclipse.p2.profile=epp.package.standard

Titanium had

eclipse.p2.profile=profile

After changing the above to match the eclipse config I was able to launch Titanium

owen gerig
  • 6,165
  • 6
  • 52
  • 91
0

This solved for me in few clicks. GoTo Eclipse - > Preference - > Java - > Installed JRE - > Add button - > Standard VM and refer the JRE Home path to /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home and add custom name. After the JRE path is given the required Jar files will be automatically added and click finish. Please make sure jdk is already installed.

Gobi M
  • 3,243
  • 5
  • 32
  • 47
  • 1
    This fix only causes apps run from within Eclipse to use the specified JVM. It has no effect on the JVM used to run Eclipse itself. – Brian de Alwis May 26 '14 at 19:34
0

For me it worked fix proposed in https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361#c25 :

#!/bin/bash

# Workaround for https://bugs.eclipse.org/411361
# "[Mac] Kepler doesn't launch without JRE 6, even if JDK 7 is installed"
#
# Put this launch.command into the same folder as Eclipse.app.
#
# If necessary, adapt JAVA_EXECUTABLE to the full path to your Java executable:

JAVA_EXECUTABLE=java

cd "$(dirname "$0")"

$JAVA_EXECUTABLE \
-Djava.library.path="$(echo plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_*/eclipse_*.so)" \
-Xms512m \
-Xmx2048m \
-Xdock:icon=Eclipse.app/Contents/Resources/Eclipse.icns \
-XstartOnFirstThread \
-Dorg.eclipse.swt.internal.carbon.smallFonts \
-XX:MaxPermSize=256m \
-jar "$(echo plugins/org.eclipse.equinox.launcher_*.jar)"  \
-os macosx \
-ws cocoa \
-arch x86_64 \
-showsplash \
-name Eclipse \
--launcher.appendVmargs \
-debug \
-showlocation \
-consolelog
bluesman
  • 51
  • 3
0

By default, your MacOSX comes with JRE 1.6.0 which is not suitable for Eclipse. To resolve issue you also need to install JDK 7 which already includes JRE 1.7.0.

Here is link that you can download.

Just select MacOS X version under Java SE Development Kit 7u79 and install it.

http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html

After installation this package, Eclipse will start without any more modification.

tolginho
  • 583
  • 9
  • 12