0

I'm getting this error in my Mac, Java 11.

I've gone through all the similar questions in stack overflow. They suggest to set JAVA_HOME properly. I think I have configured properly and ensured jni.h is present in the directory.

My environment variables

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/selvakumar/apache-maven-3.5.2/bin:/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home/bin:/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home/include

Complete ERROR

apples-MacBook-Pro:wrapper-java selvakumar$ cmake --build ./build/cmake --target quickjs-java-wrapper -j 6
[1/3] Building CXX object CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o
FAILED: CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCONFIG_BIGNUM -DCONFIG_VERSION=\"2021-03-27\" -Dquickjs_java_wrapper_EXPORTS -I/include -I/include/darwin -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -MD -MT CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o -MF CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o.d -o CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp.o -c /Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp
/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_context_jni.cpp:1:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
[2/3] Building CXX object CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o
FAILED: CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCONFIG_BIGNUM -DCONFIG_VERSION=\"2021-03-27\" -Dquickjs_java_wrapper_EXPORTS -I/include -I/include/darwin -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -MD -MT CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o -MF CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o.d -o CMakeFiles/quickjs-java-wrapper.dir/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp.o -c /Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp
In file included from /Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.cpp:4:
/Users/selvakumar/newworkspace/quickjs-wrapper/native/cpp/quickjs_wrapper.h:15:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

Still getting the error. I'm not sure what am I missing here.

Background: I'm trying to use quickjs in java using https://github.com/HarlonWang/quickjs-wrapper. Getting this error while running the command cmake --build ./build/cmake --target quickjs-java-wrapper -j 6

Please note that Nashorn is deprecated. Therefore I didn't use it.

Selvakumar Ponnusamy
  • 5,363
  • 7
  • 40
  • 78
  • Edit your question with the output of setting the JAVA_HOME environment variable and then running cmake from scratch. – Botje May 24 '23 at 14:06
  • Are you able to execute the `java` command? – Reilas May 24 '23 at 14:13
  • Provide the complete error message copied into your question, with some context lines to understand what is being executed when the error happens. – aled May 24 '23 at 14:26
  • Edited the question with complete error. @Reilas Yes, Java command is working and Java programs are running as usual – Selvakumar Ponnusamy May 24 '23 at 16:08
  • when you execute `echo $JAVA_HOME` in the terminal where you start `cmake` does it really output the correct folder? – cyberbrain May 24 '23 at 16:20
  • Or maybe a better check: when you do a `ls $ENV{JAVA_HOME}/include/` - does it contain the `jni.h`? Where it looks for that is configured in `wrapper-java/src/main/CMakeLists.txt` – cyberbrain May 24 '23 at 16:30

2 Answers2

2

The error in your edit proves that the JAVA_HOME environment variable was not set when you ran cmake to generate the build system. Just to be sure, nuke your build directory and run cmake again with the environment variable present:

$ rm -rf build/cmake
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home
$ cmake -B build/cmake .
$ cmake --build build/cmake --target quickjs-java-wrapper -j 6
Botje
  • 26,269
  • 3
  • 31
  • 41
0

Take a look at this question and answer, to an similar inquiry.
how to make jni.h be found?.

It appears you need to provide the include directory to cmake.
See, this question and answer, How to properly add include directories with CMake

Reilas
  • 3,297
  • 2
  • 4
  • 17
  • The CMake files in the linked project [do contain include_directories statements](https://github.com/HarlonWang/quickjs-wrapper/blob/main/wrapper-java/src/main/CMakeLists.txt#L18-L19), but they are dependent on an environment variable. – Botje May 25 '23 at 07:43