Skip to content

OS X JDK 1.7 failing to load #90

Description

@jahewson

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)

Activity

  1. joewhite86 commented on Nov 21, 2013

    @joewhite86
    Contributor

    At which point in your code the error comes up?

    Tested on my system (OS X 10.9 with 1.7.0_45) right now and it works.

  2. jahewson commented on Nov 21, 2013

    @jahewson
    Author

    My code was simply:

    var java = require("java");
    var list = java.newInstanceSync("java.util.ArrayList");

    The error occurs on line 2 (determined by inserting a console.log) there is no stack trace.

  3. joewhite86 commented on Nov 22, 2013

    @joewhite86
    Contributor

    Seems like the java environment isn't set up correctly on your system. The only place I found this file on mine is: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries/libserver.dylib, which is the pre-installed java version that came with previous versions of OS X.

    What are your Java environment variables? (JAVA_HOME, ...)

  4. jahewson commented on Nov 22, 2013

    @jahewson
    Author

    OS X 10.9 (Mavericks) does not come with Java installed. The Apple version of Java 1.6 is available as an update but not Java 1.7, which must be downloaded from Oracle.

    I do not have any environmental variables set regarding Java, there is no JAVA_HOME or Java directories in the PATH as Oracle's installer did not set them.

    I think the problem may be that node-java assumes that Apple's version of Java is installed, which is not necessarily true.

  5. joewhite86 commented on Nov 22, 2013

    @joewhite86
    Contributor

    No node-java works with both, pre-installed and others. If you upgraded from previous versions of osx you can indeed have the pre-installed jdk under /System/Library.

    Try setting JAVA_HOME

  6. jahewson commented on Nov 22, 2013

    @jahewson
    Author

    I have a fresh installation of Mavericks, not an upgrade. node-java needs to work out of the box with Oracle Java 7...

  7. jahewson commented on Nov 22, 2013

    @jahewson
    Author

    I've done some investigating - as you said the JDK under /System/Library/Java is present on Mavericks, but I think it's intended for system use (or is this just where Apple keeps its JDK?):

    ls /System/Library/Java/JavaVirtualMachines
    1.6.0.jdk
    

    The user-accesible (or just Oracle?) JDKs are under /Library/Java and I only have Oracle's JDK 1.7:

    ~$ ls /Library/Java/JavaVirtualMachines/
    jdk1.7.0_45.jdk
    

    The Oracle JDK 7's Home directory contents is:

    ~$ ls /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/
    COPYRIGHT               include
    LICENSE                 jre
    README.html             lib
    THIRDPARTYLICENSEREADME-JAVAFX.txt  man
    THIRDPARTYLICENSEREADME.txt     release
    bin                 src.zip
    db
    

    as you can see, there is no bundle directory, which relates to the original error message.

  8. jsdevel commented on Dec 19, 2013

    @jsdevel
    Collaborator

    I think find-java-home would help out here.

  9. jsdevel commented on Dec 21, 2013

    @jsdevel
    Collaborator

    @jahewson Can you clone my fork locally and try building that? Here's the URL: https://github.com/jsdevel/node-java.git

    I currently have PR for issue #94 open and I believe it will solve issues like this.

    @jahewson Now that 0.3.0 is published, can you try installing again with 0.3.0?

  10. TheSpyder commented on May 7, 2014

    @TheSpyder
    Contributor

    I'm still seeing this with 0.3.2, OS X 10.9.2.

    shinji:corpus spyder$ echo $JAVA_HOME
    /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home
    shinji:corpus spyder$ node corpus.js 
    <startup output>
    No Java runtime present, requesting install.
    

    I'm also using java.newInstanceSync.

  11. jsdevel commented on May 23, 2014

    @jsdevel
    Collaborator

    @joeferner should we add libserver.dylib to postInstall.js?

  12. joeferner commented on May 23, 2014

    @joeferner
    Owner

    That would probably make sense. Anyone have OSX to try it on?

  13. TheSpyder commented on May 25, 2014

    @TheSpyder
    Contributor

    I'm happy to test anything if you can give me a patch or tell me how to modify my local install :)

  14. jsdevel commented on May 25, 2014

    @jsdevel
    Collaborator

    @TheSpyder can you try adding git+https://github.com/jsdevel/node-java.git#a4c47f938903957f578c7f228f4aad34b6cfdb32 in your package.json for java?

  15. TheSpyder commented on May 25, 2014

    @TheSpyder
    Contributor
    node(94131,0x7fff7d3e0310) malloc: *** error for object 0x103f7e7c0: pointer being freed was not allocated
    *** set a breakpoint in malloc_error_break to debug
    Abort trap: 6
    

    well that was interesting :)

    Do I need to run a particular command to get more detail?

  16. 28 remaining items

  17. jsdevel commented on Jun 12, 2014

    @jsdevel
    Collaborator

    @TheSpyder is it safe to close the issue then?

  18. TheSpyder commented on Jun 12, 2014

    @TheSpyder
    Contributor

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

  19. jsdevel commented on Jun 12, 2014

    @jsdevel
    Collaborator

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

  20. seshness commented on Feb 28, 2015

    @seshness

    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
  21. added a commit that references this issue on Jan 5, 2017
  22. added a commit that references this issue on Jan 5, 2017
  23. junqdu commented on Mar 13, 2017

    @junqdu

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

  24. TheSpyder commented on Mar 16, 2017

    @TheSpyder
    Contributor

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

  25. scottellis64 commented on Oct 30, 2017

    @scottellis64

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

  26. caiyufei commented on Feb 22, 2018

    @caiyufei

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

  27. ctrueden commented on Apr 24, 2019

    @ctrueden
    Contributor

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

  28. jsdevel commented on Apr 24, 2019

    @jsdevel
    Collaborator

    nice @ctrueden ! can you open a pr?

  29. TheSpyder commented on Apr 24, 2019

    @TheSpyder
    Contributor

    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.

  30. added a commit that references this issue on Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions