joeferner / node-java

Bridge API to connect with existing Java APIs.
MIT License
1.88k stars 283 forks source link

Java install failing with : /usr/bin/ld: cannot find -ljvm #567

Open divishav opened 1 year ago

divishav commented 1 year ago

We are using node -v v18.12.1 node-gyp -v v9.1.0 on oraclelinux8-openjdk17.0.5

and getting the following error:

**_07:11:26   /usr/bin/ld: cannot find -ljvm 07:11:26   collect2: error: ld returned 1 exit status 07:11:26   make: * [nodejavabridge_bindings.target.mk:155: Release/obj.target/nodejavabridge_bindings.node] Error 1 07:11:26   make: Leaving directory '/usr/src/app/Content_Connect/nodemodules/java/build' 07:11:26   gyp ERR! build error 07:11:26   gyp ERR! stack Error: make failed with exit code: 2

Anyone faced similar issue? This works fine with JDK 11 but is failing with JDK 17. Any help is appreciated.

Below is the full log. make: Entering directory '/usr/src/app/Content_Connect/node_modules/java/build' 07:11:26     CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o 07:11:26   In file included from ../src/java.h:9, 07:11:26                    from ../src/java.cpp:1: 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker)': 07:11:26   ../node_modules/nan/nan.h:2294:62: warning: cast between incompatible function types from 'void (uv_work_t)' {aka 'void (uv_work_s)'} to 'uv_after_work_cb' {aka 'void (uv_work_s, int)'} [-Wcast-function-type] 07:11:26        , reinterpret_cast(AsyncExecuteComplete) 07:11:26                                                                 ^ 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::SetAccessor(v8::Local, v8::Local, Nan::GetterCallback, Nan::SetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)': 07:11:26   ../node_modules/nan/nan.h:2542:16: warning: 'void v8::ObjectTemplate::SetAccessor(v8::Local, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, v8::Local, v8::SideEffectType, v8::SideEffectType)' is deprecated: Do signature check in accessor [-Wdeprecated-declarations] 07:11:26        , signature); 07:11:26                   ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-function.h:15, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:33, 07:11:26                    from ../src/java.h:5, 07:11:26                    from ../src/java.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-template.h:838:8: note: declared here 07:11:26      void SetAccessor( 07:11:26           ^~~ 07:11:26     CXX(target) Release/obj.target/nodejavabridge_bindings/src/javaObject.o 07:11:26   In file included from ../src/utils.h:12, 07:11:26                    from ../src/methodCallBaton.h:5, 07:11:26                    from ../src/javaObject.h:10, 07:11:26                    from ../src/javaObject.cpp:1: 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker)': 07:11:26   ../node_modules/nan/nan.h:2294:62: warning: cast between incompatible function types from 'void (uv_work_t)' {aka 'void (uv_work_s)'} to 'uv_after_work_cb' {aka 'void (uv_work_s, int)'} [-Wcast-function-type] 07:11:26        , reinterpret_cast(AsyncExecuteComplete) 07:11:26                                                                 ^ 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::SetAccessor(v8::Local, v8::Local, Nan::GetterCallback, Nan::SetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)': 07:11:26   ../node_modules/nan/nan.h:2542:16: warning: 'void v8::ObjectTemplate::SetAccessor(v8::Local, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, v8::Local, v8::SideEffectType, v8::SideEffectType)' is deprecated: Do signature check in accessor [-Wdeprecated-declarations] 07:11:26        , signature); 07:11:26                   ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-function.h:15, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:33, 07:11:26                    from ../src/javaObject.h:5, 07:11:26                    from ../src/javaObject.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-template.h:838:8: note: declared here 07:11:26      void SetAccessor( 07:11:26           ^~~ 07:11:26     CXX(target) Release/obj.target/nodejavabridge_bindings/src/javaScope.o 07:11:26     CXX(target) Release/obj.target/nodejavabridge_bindings/src/methodCallBaton.o 07:11:26   In file included from ../src/utils.h:12, 07:11:26                    from ../src/methodCallBaton.h:5, 07:11:26                    from ../src/methodCallBaton.cpp:2: 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker)': 07:11:26   ../node_modules/nan/nan.h:2294:62: warning: cast between incompatible function types from 'void (uv_work_t)' {aka 'void (uv_work_s)'} to 'uv_after_work_cb' {aka 'void (uv_work_s, int)'} [-Wcast-function-type] 07:11:26        , reinterpret_cast(AsyncExecuteComplete) 07:11:26                                                                 ^ 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::SetAccessor(v8::Local, v8::Local, Nan::GetterCallback, Nan::SetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)': 07:11:26   ../node_modules/nan/nan.h:2542:16: warning: 'void v8::ObjectTemplate::SetAccessor(v8::Local, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, v8::Local, v8::SideEffectType, v8::SideEffectType)' is deprecated: Do signature check in accessor [-Wdeprecated-declarations] 07:11:26        , signature); 07:11:26                   ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-function.h:15, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:33, 07:11:26                    from ../src/utils.h:6, 07:11:26                    from ../src/methodCallBaton.h:5, 07:11:26                    from ../src/methodCallBaton.cpp:2: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-template.h:838:8: note: declared here 07:11:26      void SetAccessor( 07:11:26           ^~~ 07:11:26     CXX(target) Release/obj.target/nodejavabridge_bindings/src/nodeJavaBridge.o 07:11:26   In file included from ../src/java.h:9, 07:11:26                    from ../src/nodeJavaBridge.cpp:2: 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker)': 07:11:26   ../node_modules/nan/nan.h:2294:62: warning: cast between incompatible function types from 'void (uv_work_t)' {aka 'void (uv_work_s)'} to 'uv_after_work_cb' {aka 'void (uv_work_s, int)'} [-Wcast-function-type] 07:11:26        , reinterpret_cast(AsyncExecuteComplete) 07:11:26                                                                 ^ 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::SetAccessor(v8::Local, v8::Local, Nan::GetterCallback, Nan::SetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)': 07:11:26   ../node_modules/nan/nan.h:2542:16: warning: 'void v8::ObjectTemplate::SetAccessor(v8::Local, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, v8::Local, v8::SideEffectType, v8::SideEffectType)' is deprecated: Do signature check in accessor [-Wdeprecated-declarations] 07:11:26        , signature); 07:11:26                   ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-function.h:15, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:33, 07:11:26                    from ../src/java.h:5, 07:11:26                    from ../src/nodeJavaBridge.cpp:2: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-template.h:838:8: note: declared here 07:11:26      void SetAccessor( 07:11:26           ^~~ 07:11:26   In file included from ../src/java.h:6, 07:11:26                    from ../src/nodeJavaBridge.cpp:2: 07:11:26   ../src/nodeJavaBridge.cpp: At global scope: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/node.h:976:43: warning: cast between incompatible function types from 'void (v8::Local)' to 'node::addon_register_func' {aka 'void (v8::Local, v8::Local, void)'} [-Wcast-function-type] 07:11:26          (node::addon_register_func) (regfunc),                           07:11:26                                              ^ 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/node.h:1010:3: note: in expansion of macro 'NODE_MODULE_X' 07:11:26      NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage) 07:11:26      ^~~~~ 07:11:26   ../src/nodeJavaBridge.cpp:11:3: note: in expansion of macro 'NODE_MODULE' 07:11:26      NODE_MODULE(nodejavabridge_bindings, init); 07:11:26      ^~~ 07:11:26     CXX(target) Release/obj.target/nodejavabridge_bindings/src/utils.o 07:11:26   In file included from ../src/utils.h:12, 07:11:26                    from ../src/utils.cpp:1: 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::AsyncQueueWorker(Nan::AsyncWorker)': 07:11:26   ../node_modules/nan/nan.h:2294:62: warning: cast between incompatible function types from 'void (uv_work_t)' {aka 'void (uv_work_s)'} to 'uv_after_work_cb' {aka 'void (uv_work_s, int)'} [-Wcast-function-type] 07:11:26        , reinterpret_cast(AsyncExecuteComplete) 07:11:26                                                                 ^ 07:11:26   ../node_modules/nan/nan.h: In function 'void Nan::SetAccessor(v8::Local, v8::Local, Nan::GetterCallback, Nan::SetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)': 07:11:26   ../node_modules/nan/nan.h:2542:16: warning: 'void v8::ObjectTemplate::SetAccessor(v8::Local, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local, v8::AccessControl, v8::PropertyAttribute, v8::Local, v8::SideEffectType, v8::SideEffectType)' is deprecated: Do signature check in accessor [-Wdeprecated-declarations] 07:11:26        , signature); 07:11:26                   ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-function.h:15, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:33, 07:11:26                    from ../src/utils.h:6, 07:11:26                    from ../src/utils.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-template.h:838:8: note: declared here 07:11:26      void SetAccessor( 07:11:26           ^~~ 07:11:26   ../src/utils.cpp: In function 'v8::Local javaExceptionToV8(Java, JNIEnv, jthrowable, const string&)': 07:11:26   ../src/utils.cpp:455:128: warning: ignoring return value of 'v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)', declared with attribute warn_unused_result [-Wunused-result] 07:11:26        ((v8::Object)v8ex)->Set(Nan::GetCurrentContext(), Nan::New("cause").ToLocalChecked(), javaToV8(java, env, ex)); 07:11:26                                                                                                                                   ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-array-buffer.h:13, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:24, 07:11:26                    from ../src/utils.h:6, 07:11:26                    from ../src/utils.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-object.h:244:37: note: declared here 07:11:26      V8_WARN_UNUSED_RESULT Maybe Set(Local context, 07:11:26                                        ^~~ 07:11:26   ../src/utils.cpp: In function 'v8::Local javaArrayToV8(Java, JNIEnv, jobjectArray)': 07:11:26   ../src/utils.cpp:648:76: warning: ignoring return value of 'v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)', declared with attribute warn_unused_result [-Wunused-result] 07:11:26            result->Set(Nan::GetCurrentContext(), i, JavaObject::New(java, obj)); 07:11:26                                                                               ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-array-buffer.h:13, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:24, 07:11:26                    from ../src/utils.h:6, 07:11:26                    from ../src/utils.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-object.h:247:37: note: declared here 07:11:26      V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index, 07:11:26                                        ^~~ 07:11:26   ../src/utils.cpp:658:54: warning: ignoring return value of 'v8::Maybe v8::Object::Set(v8::Local, uint32_t, v8::Local)', declared with attribute warn_unused_result [-Wunused-result] 07:11:26            result->Set(Nan::GetCurrentContext(), i, item); 07:11:26                                                         ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-array-buffer.h:13, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:24, 07:11:26                    from ../src/utils.h:6, 07:11:26                    from ../src/utils.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-object.h:247:37: note: declared here 07:11:26      V8_WARN_UNUSED_RESULT Maybe Set(Local context, uint32_t index, 07:11:26                                        ^~~ 07:11:26   ../src/utils.cpp: In function 'v8::Local javaToV8(Java, JNIEnv, jobject, DynamicProxyData)': 07:11:26   ../src/utils.cpp:721:168: warning: ignoring return value of 'v8::Maybe v8::Object::Set(v8::Local, v8::Local, v8::Local)', declared with attribute warn_unused_result [-Wunused-result] 07:11:26            v8ResultNumberObject->Set(Nan::GetCurrentContext(), Nan::New("longValue").ToLocalChecked(), Nan::New(strValue.c_str()).ToLocalChecked()); 07:11:26                                                                                                                                                                           ^ 07:11:26   In file included from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-array-buffer.h:13, 07:11:26                    from /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8.h:24, 07:11:26                    from ../src/utils.h:6, 07:11:26                    from ../src/utils.cpp:1: 07:11:26   /home/ccadmin/.cache/node-gyp/18.12.1/include/node/v8-object.h:244:37: note: declared here 07:11:26      V8_WARN_UNUSED_RESULT Maybe Set(Local context, 07:11:26                                        ^~~ 07:11:26     SOLINK_MODULE(target) Release/obj.target/nodejavabridge_bindings.node 07:11:26   /usr/bin/ld: cannot find -ljvm 07:11:26   collect2: error: ld returned 1 exit status 07:11:26   make: *** [nodejavabridge_bindings.target.mk:155: Release/obj.target/nodejavabridge_bindings.node] Error 1 07:11:26   make: Leaving directory '/usr/src/app/Content_Connect/node_modules/java/build' 07:11:26   gyp ERR! build error 07:11:26   gyp ERR! stack Error: make failed with exit code: 2 07:11:26   gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23) 07:11:26   gyp ERR! stack     at ChildProcess.emit (node:events:513:28) 07:11:26   gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12) 07:11:26   gyp ERR! System Linux 3.10.0-862.14.4.el7.x86_64 07:11:26   gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" 07:11:26   gyp ERR! cwd /usr/src/app/Content_Connect/node_modules/java 07:11:26   gyp ERR! node -v v18.12.1 07:11:26   gyp ERR! node-gyp -v v9.1.0 07:11:26   gyp ERR! not ok

posenato commented 1 year ago

In my experience, the last compatible Node version with node-java v0.12.2 is v16.19.0.

divishav commented 1 year ago

@posenato But it was working with Node 18.12.1 with OpenJdk 11, it is only with Open Jdk 17 it is failing.

ltkrbk commented 1 year ago

I just solve this problem. This problem is cause by the script find_java_libdir.sh . You can cloen the rep and open the find_java_libdir.sh, change to line: ` if [[ "${java_version}" =~ (6|7|8) && "${os}" != "zos" ]]; then

to

if [[ "${java_version}" =~ (6|8) && "${os}" != "zos" ]]; then

and

if [[ "${os}" == "linux" && ! "${java_version}" =~ (6|7|8) ]]; then

to

if [[ "${os}" == "linux" && ! "${java_version}" =~ (6|8) ]]; then and put the rep to your node project dir, and install the module via local: npm install ./node-java-master `

DavidCosiallsSEATCODE commented 3 months ago

If you're in macOS:

I have solved it by installing the openJDK from brew with: brew install openJDK@8

and following the command instructions:

For the system Java wrappers to find this JDK, symlink it with sudo ln -sfn /usr/local/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-8.jdk openjdk@8 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula.

If you need to have openjdk@8 first in your PATH, run: echo 'export PATH="/usr/local/opt/openjdk@8/bin:$PATH"' >> ~/.zshrc

For compilers to find openjdk@8 you may need to set: export CPPFLAGS="-I/usr/local/opt/openjdk@8/include"