javacmakejava-native-interfaceeclipse-temurin

CMake is not detecting JNI properly with Temurin JDK 8 on macOS


I am building a library on macOS v11 (Big Sur) using Java 8 from Adoptium (Eclipse Temurin).

To install Java, I am using the following commands:

brew tap homebrew/cask-versions
brew install --cask temurin8

Then, I export JAVA_HOME like this:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

And it properly exports it. When I execute echo $JAVA_HOME, it returns:

/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home

However, while building the library, it tries to find JNI, and it is returning the following lines:

CMake Error at /usr/local/Cellar/cmake/3.24.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find JNI (missing: JAVA_INCLUDED_PATH JAVA_INCLUDED_PATH2 AWT)

Is there anything else necessary to make this work on macOS?

Notes:


Solution

  • I was finally able to solve this by setting the requested variables as flags for CMake. I just appended the following to my CMake call:

    cmake ... -DJAVA_HOME=$(/usr/libexec/java_home -v 1.8) -DJAVA_INCLUDE_PATH=$(/usr/libexec/java_home -v 1.8)/include -DJAVA_INCLUDE_PATH2=$(/usr/libexec/java_home -v 1.8)/include/darwin -DJAVA_AWT_INCLUDE_PATH=$(/usr/libexec/java_home -v 1.8)/include