Tuesday, November 16, 2021

[SOLVED] CMake cannot find Java on Linux "Could NOT find Java (missing: Java_JAVAH_EXECUTABLE)"

Issue

I'm encountering a CMake error suggesting it cannot find Java (JDK I think?):

Could NOT find Java (missing: Java_JAVAH_EXECUTABLE) (found version
  "1.8.0_181")

However, when I run:

which javac

I get:

/bin/javac

but setting:

export JAVA_HOME=/bin/javac

and re-compiling does not solve the problem.

Anybody encountered this before?


Solution

It looks like cmake is looking for javah not javac. You're using Java 1.8, so you should have javah installed. (It has been removed in a later version, and instead of javah you're supposed to use javac -h)

Make sure cmake can find the javah tool by setting JAVA_HOME so that it points at the Java 8 installation directory (typically under /usr/lib/jvm on a Linux system)



Answered By - Joni