node-java
node-java copied to clipboard
Issues with JDK 13 and 14
When I am using JDK 8 and 11, it seems to work fine.
But with JDK 13 and 14, I am getting this error:
SOLINK_MODULE(target) Release/nodejavabridge_bindings.node
ld: warning: directory not found for option '-L/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home/lib/jli'
ld: library not found for -ljli
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/nodejavabridge_bindings.node] Error 1
gyp ERR! build error
gyp ERR! stack Error: make
failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/saagarwa/.nvs/node/10.15.3/x64/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:189:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/Users//.nvs/node/10.15.3/x64/bin/node" "/Users/saagarwa/.nvs/node/10.15.3/x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users//node_modules/java
gyp ERR! node -v v10.15.3
Actually in JDK 14 (and 13), libjli.dylib is under: /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home/lib/libjli.dylib
But in JDK 8 and 11, its under: /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/lib/jli/libjli.dylib
same issue when running npm i java
.
please see this answer for possible fix: https://github.com/joeferner/node-java/issues/494#issuecomment-593880511
it looks like this code needs to be changed to account for the directory change in 13-14 https://github.com/joeferner/node-java/blob/09f87eeb36110b0f9d201074050c7f9dc3f838bd/find_java_libdir.sh#L48
$ brew install openjdk
$ java -version
openjdk version "14.0.1" 2020-04-14
OpenJDK Runtime Environment (build 14.0.1+14)
OpenJDK 64-Bit Server VM (build 14.0.1+14, mixed mode, sharing)
$ CXX="clang++ -I${JAVA_HOME}/include/darwin/" npm install --save java
installs correctly. However, when using import, I receive the following error:
dyld: lazy symbol binding failed: Symbol not found: _JNI_CreateJavaVM
Referenced from: (redacted)/node_modules/java/build/Release/nodejavabridge_bindings.node
Expected in: flat namespace
dyld: Symbol not found: _JNI_CreateJavaVM
Referenced from: (redacted)/node_modules/java/build/Release/nodejavabridge_bindings.node
Expected in: flat namespace
Same issue exists for OpenJDK 11.
Calling node this way resolves the issue:
$ DYLD_INSERT_LIBRARIES=${JAVA_HOME}/lib/server/libjvm.dylib node
lib_dir="${jre_dir}/jli"
I forked this change, https://github.com/danielwsutton/node-java/commit/1e30ba786a6965fd8df2b643a5d962b06891d4fb
From:
lib_dir="${jre_dir}/jli"
To:
if [[ -f ${jre_dir}/jli/libjli.dylib ]]; then lib_dir="${jre_dir}"/jli; else lib_dir="${jre_dir}"; fi
So far it seems to be working,
I testing on adoptopenjdk8 and adoptopenjdk12 , your mileage may vary,
I did run into a new issue after getting past the original problem, but can't seem to repro it locally, only when running it on aws, so that's progress atleast...
CXX(target) Release/obj.target/nodejavabridge_bindings/src/utils.o
../src/utils.cpp:488:16: error: no member named 'GetBackingStore' in 'v8::ArrayBuffer'
memcpy(ab->GetBackingStore()->Data(), elems, length);
~~ ^
The above issue with no member named 'GetBackingStore'
was resolved by using node 14.8.0
It seems like when you switch to a new version of Java, it forces you into a newer version of Node as well.
I am having the same issue on macOS with JDK11:
- macOS 11.4
- node v14.8.0
- AdoptOpenJDK build 11.0.10+9 (installed using sdkman JAVA_HOME=/Users/<myuser>/.sdkman/candidates/java/current)
2 issues, and workaround:
- on first
npm i java
:
/Users/<myuser>/.sdkman/candidates/java/current/include/jni.h:45:10: fatal error: 'jni_md.h' file not found`
Workaround: cp ~/.sdkman/candidates/java/current/include/darwin/jni_md.h ~/.sdkman/candidates/java/current/include/jni_md.h
- after applying workaround#1, the pkg is installed, and when running (any script that loads java):
dyld: lazy symbol binding failed: Symbol not found: _JNI_CreateJavaVM
Referenced from: /path/to/my/project/node_modules/java/build/Release/nodejavabridge_bindings.node
Expected in: flat namespace
Workaround (suggested here): DYLD_INSERT_LIBRARIES=${JAVA_HOME}/lib/server/libjvm.dylib node somescript.js
Is there a solution that can be applied to this lib without having to run these workarounds?
I got tired of trying all these suggestions and copied libjli.dylib (currently in /Library/Java//JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/lib/libjli.dylib
) into the path that npm wants it, /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/jre/lib/jli