javascript - jni.h file not found - installing node-java module on OS X El Capitan - Stack Overflow

I am trying to install node-java module which allows Node.js to connect to existing Java APIs. Here is

I am trying to install node-java module which allows Node.js to connect to existing Java APIs. Here is the mand I am using to install this module:

sudo npm install java -g

Here is the stack trace of the error I am getting:

> [email protected] install /usr/local/lib/node_modules/java
> node-gyp rebuild

CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o
In file included from ../src/java.cpp:1:
../src/java.h:7:10: fatal error: 'jni.h' file not found
#include <jni.h>
     ^
1 error generated.
make: *** [Release/obj.target/nodejavabridge_bindings/src/java.o]         Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit     (/usr/local/lib/node_modules/npm/node_modules/node-   gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit    (child_process.js:810:12)
gyp ERR! System Darwin 15.6.0
gyp ERR! mand "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/java
gyp ERR! node -v v0.10.33
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

The interesting thing to note here is that I am able to install the same module locally with npm install java mand which installs it in:

/Users/[$my_username]/node_modules

Here is some additional info:

Node

v0.10.33

Java

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

$JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/include

locate jni.h

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/include/jni.h
 /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/include/jni.h

I am trying to install node-java module which allows Node.js to connect to existing Java APIs. Here is the mand I am using to install this module:

sudo npm install java -g

Here is the stack trace of the error I am getting:

> [email protected] install /usr/local/lib/node_modules/java
> node-gyp rebuild

CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o
In file included from ../src/java.cpp:1:
../src/java.h:7:10: fatal error: 'jni.h' file not found
#include <jni.h>
     ^
1 error generated.
make: *** [Release/obj.target/nodejavabridge_bindings/src/java.o]         Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit     (/usr/local/lib/node_modules/npm/node_modules/node-   gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit    (child_process.js:810:12)
gyp ERR! System Darwin 15.6.0
gyp ERR! mand "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/java
gyp ERR! node -v v0.10.33
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok

The interesting thing to note here is that I am able to install the same module locally with npm install java mand which installs it in:

/Users/[$my_username]/node_modules

Here is some additional info:

Node

v0.10.33

Java

java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

$JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/include

locate jni.h

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-migrator/sdk/MacOSX.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/jni.h
/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/include/jni.h
 /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/include/jni.h
Share Improve this question edited Sep 12, 2016 at 19:38 Nik_stack asked Sep 10, 2016 at 16:29 Nik_stackNik_stack 2132 gold badges8 silver badges17 bronze badges 2
  • To my knowledge sudo uses a different environment so it probably doesn't have your JAVA_HOME – user2543253 Commented Sep 13, 2016 at 9:09
  • Did you find a solution? – Jason Harrison Commented Nov 25, 2016 at 20:31
Add a ment  | 

1 Answer 1

Reset to default 5

I know this post is old but it es up as the number one search and this is how I was able to resolve this issue when I tried to install node-java using Java 1.8

The JAVA_HOME is pointed to the wrong location.

it should be:

/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/

The best way to set this properly is by exporting it:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0`

Within Mac systems, I noticed that if you don't include the 0 at the end of the specified versions it will pull the JRE location, not the JDK which is what node-gyp uses.

also, you want to verify that JAVA_HOME is exported properly you can verify this by running the following mand in your terminal:

echo $JAVA_HOME

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745302417a4621515.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信