Alberto Casas Ortiz
Alberto Casas Ortiz

Reputation: 895

CMake not detecting JNI properly with Temuring jdk 8 in MacOS

I am building a library on Mac 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:

Thank you.

Edit:

Upvotes: 3

Views: 1310

Answers (1)

Alberto Casas Ortiz
Alberto Casas Ortiz

Reputation: 895

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

Upvotes: 3

Related Questions