Adding a JDK and sources to Eclipse on a Mac

I just downloaded Eclipse on my Mac after a good six months without needing it and had numerous issues using it. First, it wouldn’t start and gave the error message below.

Alert: The JVM shared library "/Library/Java/JavaVirtualMachines/1.7.0.jdk" does not contain the JNI_CreateJavaVM symbol.

I realised that the openjdk 1.7.0 package I’d installed must be somehow overriding or interfering with the 1.6.0 JDK that Apple installs by default. So I went into Applications > Utilities > Java Preferences. As soon as I opened that I was prompted by a message that said that in order to open Java Preferences I must install a Java 6 runtime and asked me if I would like to do so. I obviously said yes after which I reviewed the order of JDKs in Java Preferences which was correct.

I also removed the openjdk 1.7.0 package I’d installed earlier to prevent it from disrupting my work again by running the command below which removed this entry from Java Preferences.

sudo rm -rf /Library/Java/JavaVirtualMachines/1.7.0.jdk/

Next, as I created a Java project, I realised Eclipse was still operating with a JRE and unsurprisingly I couldn’t access the source code of the JDK libraries. To resolve both these issues at once I went into Eclipse > Preferences > Java > Installed JREs > Add and added the following path.


You’ll notice this path contains the essential src.jar. Then I went into Project > Properties > Java Build Path > Libraries, removed the existing JRE and added the new JDK. I was now able to open String.class and see the source and all was well.

Why is Java still such a nightmare on OS X after all this time? I really hope it improves with Java 8. Anyway, I wrote all this up in the hope that it helps others also struggling with such problems.

4 thoughts on “Adding a JDK and sources to Eclipse on a Mac”

Leave a Reply