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

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.

joewhite86 avatar Nov 21 '13 14:11 joewhite86

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.

jahewson avatar Nov 21 '13 15:11 jahewson

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, ...)

joewhite86 avatar Nov 22 '13 09:11 joewhite86

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.

jahewson avatar Nov 22 '13 10:11 jahewson

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

joewhite86 avatar Nov 22 '13 11:11 joewhite86

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

jahewson avatar Nov 22 '13 16:11 jahewson

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.

jahewson avatar Nov 22 '13 16:11 jahewson

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

jsdevel avatar Dec 19 '13 07:12 jsdevel

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

jsdevel avatar Dec 21 '13 19:12 jsdevel

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.

TheSpyder avatar May 07 '14 01:05 TheSpyder

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

jsdevel avatar May 23 '14 09:05 jsdevel

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

joeferner avatar May 23 '14 14:05 joeferner

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

TheSpyder avatar May 25 '14 07:05 TheSpyder

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

jsdevel avatar May 25 '14 08:05 jsdevel

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?

TheSpyder avatar May 25 '14 08:05 TheSpyder

hmmmm.... That is interesting. You're getting a different error now though which is promising!

Can you do this and paste the output of ~/contents-of-java-home.txt?

  1. cd node_modules/java
  2. cd "node findJavaHome.js"
  3. find . > ~/contents-of-java-home.txt

cc @joeferner. I'm guessing that error is related to node-java trying to free a pointer that hasn't been created yet?

jsdevel avatar May 25 '14 09:05 jsdevel

I don't want to spam anyone's inbox, so I put it on pastebin :)

http://pastebin.com/mAxiwt05

TheSpyder avatar May 25 '14 09:05 TheSpyder

@TheSpyder @joeferner looks like that error is happening for other Mavericks users without node-java https://www.bountysource.com/issues/1126096-tree-diffindex-pointer-being-freed-was-not-allocated.

@TheSpyder what version of java and node are you using?

jsdevel avatar May 25 '14 09:05 jsdevel

ahh, well I have upgraded node recently. I try to keep it up to date.

Node v0.10.28 Java latest (tried both 1.7.0_55 and 1.8.0_05 by changing JAVA_HOME)

I have, however, installed node via homebrew if that makes any difference.

TheSpyder avatar May 25 '14 09:05 TheSpyder

@TheSpyder you might try with other versions of node if you can.

jsdevel avatar May 25 '14 09:05 jsdevel