OS X JDK 1.7 failing to load
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)
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 I'm curious now what the actual issue was originally. I'm a bit confused ATM. Thoughts?
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 is it safe to close the issue then?
Yes. I don't believe you can fix this. It's worth adding a note (and possibly my suggested workarounds) to the readme, though.
Thanks @TheSpyder! I think for now we can close it. Can you submit a PR with the README addition?
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
@TheSpyder any idea why JDK doesn't advertise itself as supporting JNI?
@junqdu no idea. I don't think Oracle cares about Java on OS X much anymore.
Adding JNI to the list of JVMCapabilities worked perfectly for me.
@TheSpyder Thanks for your solution, adding JNI also works for me! Thanks !!
@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.
nice @ctrueden ! can you open a pr?
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.