I am using cmake 2.8.7 on Ubuntu 12.04 amd64. The installed OpenJDK JRE components in my system are listed below :
$ sudo dpkg --list | grep jdk
openjdk-6-jre 6b27-1.12.5-0ubuntu0.12.04.1 OpenJDK Java runtime, using Hotspot JIT
openjdk-6-jre-headless 6b27-1.12.5-0ubuntu0.12.04.1 OpenJDK Java runtime, using Hotspot JIT (headless)
openjdk-6-jre-lib 6b27-1.12.5-0ubuntu0.12.04.1 OpenJDK Java runtime (architecture independent libraries)
However, I am not using the OpenJDK JRE components. I have manually installed Oracle Java 7 JDK in "/usr/lib/jvm/jdk1.7.0_25" and have used "update-alternatives" to point "java" to my installed Oracle Java 7 JDK. I have not set any "JAVA_HOME", "JAVA_BIN", "CLASSPATH" environment variables and the manually installed Oracle Java 7 JDK seems work OK in Eclipse 4.3.
The problem is that when I use "find_package(JNI)" in cmake and use the "message()" function to show the JNI variables, I have the following result :
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
JNI_FOUND = FALSE
JNI_LIBRARIES = /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libjawt.so;/usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so
JAVA_INCLUDE_PATH = JAVA_INCLUDE_PATH-NOTFOUND
JAVA_INCLUDE_PATH2 = JAVA_INCLUDE_PATH2-NOTFOUND
JAVA_AWT_INCLUDE_PATH = JAVA_AWT_INCLUDE_PATH-NOTFOUND
JAVA_JVM_LIBRARY = /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server/libjvm.so
JAVA_AWT_LIBRARY = /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/libjawt.so
JNI_INCLUDE_DIRS = JAVA_INCLUDE_PATH-NOTFOUND;JAVA_INCLUDE_PATH2-NOTFOUND;JAVA_AWT_INCLUDE_PATH-NOTFOUND
The "find_package(JNI)" seems could find some of the Java components related to the OpenJDK JRE and could not find my current Oracle Java 7 JDK components pointed by "update-alternatives".
I want to know that is there any bug in the "FindJNI.cmake" file and what I have missed in the Oracle Java 7 JDK setup so that cmake "find_package(JNI)" could work properly.
Thanks for any suggestion.
You can manually modify FindJNI.cmake to help it find your installed JDK. See this gist:
https://gist.github.com/emchristiansen/6845954
It's a shame this script hasn't been updated, but maybe not a surprise, given that CMake is such a disaster.
EDIT: A more straightforward solution is to set
JAVA_HOME
properly. With OpenJDK 7 installed, I set it with:export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
If you have oracle jdk 7 installed on your system, as was my case, you might run into the issues while building opencv. For resolving those issues, I had to edit, /usr/share/cmake-2.8/Modules/FindJNI.cmake file. In this file, I commented out the lines with references to openjdk and default and added references of oracle jdk 7 as shown below.
and in the section where the script looks for include library...
Then I followed exact instructions to build the openCV for android.
I had to comment out openjdk and default related lines, since they were conflicting with oracle installations.