3

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:

  • I installed cmake using brew (brew install cmake).
  • I have already searched in Google and StackOverflow, and none of the proposed solutions worked (I have also checked the recommended similar questions while creating this one).
  • I checked the variable values in the FindJNI.cmake file and everything seems correct (it should find it).
    • In FindJNI.cmake, the value of JAVA_AWT_INCLUDE_DIRECTORIES is correct (/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/include), and jni.h is inside that directory. However, find_path(JAVA_INCLUDE_PATH 'jni.h' $(JAVA_AWT_INCLUDE_DIRECTORIES)) is not setting JAVA_INCLUDE_PATH properly.
    • I created a dummy project using find_path(TEST 'jni.h' '/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/include'), looking for jni.h and it works. TEST contains the correct value.

Thank you.

Edit:

  • This is the call to find_package:

     find_package(JNI 1.7 REQUIRED)
    
  • Can you show the `find_package` invocation for JNI? – Botje Nov 02 '22 at 07:42
  • Hi @Botje, I was finally able to compile this. It does not actually "solve" the problem, since I had to set the variables manually, but this worked for me. I posted an answer with it. Regarding the `find_package` invocation, I just added it to my question. It indicates the minimum version as 1.7. I am using 1.8, so it should not be a problem. – Alberto Casas Ortiz Nov 02 '22 at 19:38
  • Thanks. I tried to reproduce your issue but could not. All the mentioned variables are just present and correct for me. – Botje Nov 03 '22 at 10:03

1 Answers1

1

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