How to find Java path via Cmake on Mac

59 views Asked by At

I am currently having issues with getting my code to get Java libraries on mac.

This is the error i get keep getting when compiling:

\-- Java version check failed: /Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home/bin/java -version returned an error: ""

This indirectly sets ${JAVA_INCLUDE_PATH}, ${JNI_INCLUDE_DIRS} and other java paths to '/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home.

The problem is jdk-18.0.1.1.jdk no longer exist on my system, so how do i make my code use another java jdk version.

I tried installing jdk 1.8 and tried exporting the locatino of the in the zsh shell like this:

export JAVA_HOME=$(/usr/libexec/java_home -v1.8.0_292)

However the only way i get my code to run is when i point the java path to the exact location, like this:

set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include")
set(JAVA_AWT_INCLUDE_PATH "$ENV{JAVA_HOME}/include")
set(JAVA_INCLUDE_PATH2 "$ENV{JAVA_HOME}/include/darwin")
set(JAVA_AWT_LIBRARY "$ENV{JAVA_HOME}/lib/libjawt.dylib")
set(JAVA_JVM_LIBRARY "$ENV{JAVA_HOME}/lib/server/libjvm.dylib")
0

There are 0 answers