4

So I am trying to build cmake so I can use it with a Java GUI I am designing. I have ready many questions on here, and looked up several tutorials on how to do this, and the one commonality is they all seem to say, if it does not work, set JAVA_HOME to the JDK location. But I have done that and it still does not work.

The cmake output for java is this:

--   Java:                          
--     ant:                         /usr/bin/ant (ver 1.10.3)
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO

and to show I have JAVA_HOME set:

echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64
which java
/usr/bin/java

namei /usr/bin/java
f: /usr/bin/java
 d /
 d usr
 d bin
 l java -> /etc/alternatives/java
   d /
   d etc
   d alternatives
   l java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
     d /
     d usr
     d lib
     d jvm
     d java-11-openjdk-amd64
     d bin
     - java

echo $PATH
/usr/lib/jvm/java-11-openjdk-amd64/bin:/usr/local/sbin:/usr/local/bin:/usr      /sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

So I have my environment variable set, and it finds ant just fine, but refused to find JNI. Anyone have any ideas why?

SassyViking
  • 109
  • 1
  • 2
  • 6
  • "JNI" usually means the JNI header files. Have you installed a JDK (not just a JRE)? You also may set the include path to the JNI header files manually (add to include dirs). – Robert Dec 21 '18 at 15:13
  • I have installed JDK 11, So cmake needs an include dirs prameter that points to where the jni header actually is (/usr/lib/jvm/java-11-openjdk-amd64/include/jni.h)? – SassyViking Dec 21 '18 at 17:15
  • Yes, the path to the include directory where the jni header files are located have to be specified. I am not sure if there ever was some sore of environment variable that points to it. Usually you have to specify the path manually. – Robert Dec 22 '18 at 12:18
  • Thank you for your comments, That helped. Almost everything else i could find just said set the environment variable. After digging in the cmake gui, the only path it could not find was to the Java_awt_include directory. Once I added that it worked. If you want to add a solution so I can upvote it and mark as correct, feel free to do so, Otherwise, thanks again. – SassyViking Jan 03 '19 at 14:42

2 Answers2

0

Seems like you have to manually specify the path to the include directory where the jni header files are located, for example /usr/lib/jvm/java-11-openjdk-amd64/include/.

If the used build script uses the environment variable JAVA_HOME it should search for the JNI include files in the directory $JAVA_HOME/include. This path is AFAIK currently working for at least all Java versions 8-11.

Robert
  • 39,162
  • 17
  • 99
  • 152
0

Please try: FindJNI

find_package(JNI)

if (JNI_FOUND)
    message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
    message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
myuce
  • 1,321
  • 1
  • 19
  • 29