node-java icon indicating copy to clipboard operation
node-java copied to clipboard

OS X JDK 1.7 failing to load

Open jahewson opened this issue 13 years ago • 54 comments

I'm using OS X 10.9 with Sun's JDK 1.7 and always get the following error:

JavaVM: Failed to load JVM: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.
JavaVM: Failed to load JVM: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bundle/Libraries/libserver.dylib
JavaVM FATAL: Failed to load the jvm library.
Segmentation fault: 11

Indeed, the folder /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/bundle does not exist on my system.

I'm using Sun's JDK 1.7, and do not have Apple's installed. The output of java -version is:

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

jahewson avatar Nov 14 '13 23:11 jahewson

Yeah, I suspect homebrew was interfering for a while there. One of their recent updates removed /usr/local/bin/gcc in favour of a more specific /usr/local/bin/gcc-4.8. This means running gcc now uses /usr/bin/gcc (which is just clang).

I don't need to set CXX at all anymore (osx 10.9.3, Xcode 5.1.1).

TheSpyder avatar Jun 12 '14 10:06 TheSpyder

@TheSpyder I'm curious now what the actual issue was originally. I'm a bit confused ATM. Thoughts?

jsdevel avatar Jun 12 '14 14:06 jsdevel

I'm not sure exactly what was causing the malloc and dyld errors, but I strongly suspect the mid-may Xcode update. Homebrew likely took some time to catch up to whatever Apple did.

Right now, we're back to just the Java 6 issue.

TheSpyder avatar Jun 12 '14 22:06 TheSpyder

@TheSpyder is it safe to close the issue then?

jsdevel avatar Jun 12 '14 22:06 jsdevel

Yes. I don't believe you can fix this. It's worth adding a note (and possibly my suggested workarounds) to the readme, though.

TheSpyder avatar Jun 12 '14 23:06 TheSpyder

Thanks @TheSpyder! I think for now we can close it. Can you submit a PR with the README addition?

jsdevel avatar Jun 12 '14 23:06 jsdevel

Thanks, @TheSpyder! That was super helpful. It looks like the homebrew cask installation for Java 7 now applies your first suggested workaround: https://github.com/caskroom/homebrew-versions/blob/master/Casks/java7.rb#L17

Installation steps for the next person to stumble upon this issue:

$ brew install caskroom/cask/brew-cask
$ brew tap caskroom/homebrew-versions
$ brew cask install java7

seshness avatar Feb 28 '15 07:02 seshness

@TheSpyder any idea why JDK doesn't advertise itself as supporting JNI?

junqdu avatar Mar 13 '17 21:03 junqdu

@junqdu no idea. I don't think Oracle cares about Java on OS X much anymore.

TheSpyder avatar Mar 16 '17 01:03 TheSpyder

Adding JNI to the list of JVMCapabilities worked perfectly for me.

scottellis64 avatar Oct 30 '17 18:10 scottellis64

@TheSpyder Thanks for your solution, adding JNI also works for me! Thanks !!

caiyufei avatar Feb 22 '18 06:02 caiyufei

@TheSpyder @jsdevel There is another, better way to avoid this horrible issue: load libjli before loading libjvm. The ImageJ project uses this trick for its launcher successfully. And here is another example of a project using this solution. A big advantage of this approach is that users do not need to manually tweak their Java installations in order to get up and running.

ctrueden avatar Apr 24 '19 17:04 ctrueden

nice @ctrueden ! can you open a pr?

jsdevel avatar Apr 24 '19 18:04 jsdevel

Interesting. That ImageJ dev seems to like to rant about Apple. I'm amused that there were three working methods to fix the same issue; perhaps the config patch only worked by accident.

Your second link (xamarin) points to this OpenJDK bug, which was fixed in Java 9: https://bugs.openjdk.java.net/browse/JDK-7131356

So while this change is probably harmless on new releases, it seems only necessary on now-unsupported versions of Java (Java 8 fell out of Oracle support in Jan 2019).

A big advantage of this approach is that users do not need to manually tweak their Java installations in order to get up and running.

Note that manual patching wasn't required for homebrew users, the cask did that in a post install script. Although that was been removed after someone discovered it didn't makes sense in Java 11.

TheSpyder avatar Apr 24 '19 22:04 TheSpyder