Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with JDK 13 and 14 #497

Open
saagarwa opened this issue Apr 15, 2020 · 8 comments
Open

Issues with JDK 13 and 14 #497

saagarwa opened this issue Apr 15, 2020 · 8 comments

Comments

@saagarwa
Copy link

saagarwa commented Apr 15, 2020

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

@ongkristopher
Copy link

ongkristopher commented May 25, 2020

same issue when running npm i java.

please see this answer for possible fix: #494 (comment)

@chazguerrero
Copy link

it looks like this code needs to be changed to account for the directory change in 13-14

lib_dir="${jre_dir}/jli"

@doctorpangloss
Copy link

doctorpangloss commented Jul 31, 2020

$ 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

@danielwsutton
Copy link

lib_dir="${jre_dir}/jli"

I forked this change, danielwsutton@1e30ba7

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,

@danielwsutton
Copy link

danielwsutton commented Aug 19, 2020

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);
           ~~  ^

@danielwsutton
Copy link

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.

@natiz
Copy link

natiz commented Jul 4, 2021

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:

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

  1. 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?

@fercook
Copy link

fercook commented Jan 4, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants