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.
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
${_JAVA_HOME}/jre/lib/{libarch}
${_JAVA_HOME}/jre/lib
${_JAVA_HOME}/lib
${_JAVA_HOME}
/usr/lib
/usr/local/lib
/usr/lib/jvm/java/lib
/usr/lib/java/jre/lib/{libarch}
/usr/lib/jvm/jre/lib/{libarch}
/usr/local/lib/java/jre/lib/{libarch}
/usr/local/share/java/jre/lib/{libarch}
/usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
/usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
/opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
/usr/lib/jvm/java-6-sun/jre/lib/{libarch}
/usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
/usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch} # can this one be removed according to #8821 ? Alex
#/usr/lib/jvm/java-6-openjdk/jre/lib/{libarch} # Commented by Atul
#/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/{libarch} # fedora
# Debian specific paths for default JVM
#/usr/lib/jvm/default-java/jre/lib/{libarch} # Commented by Atul
#/usr/lib/jvm/default-java/jre/lib # Commented by Atul
#/usr/lib/jvm/default-java/lib # Commented by Atul
# OpenBSD specific paths for default JVM
/usr/local/jdk-1.7.0/jre/lib/{libarch}
/usr/local/jre-1.7.0/lib/{libarch}
/usr/local/jdk-1.6.0/jre/lib/{libarch}
/usr/local/jre-1.6.0/lib/{libarch}
/usr/lib/jvm/java-7-oracle/jre/lib/{libarch} # This is added Atul
)
and in the section where the script looks for include library...
set(JAVA_AWT_INCLUDE_DIRECTORIES
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
${_JAVA_HOME}/include
/usr/include
/usr/local/include
/usr/lib/java/include
/usr/local/lib/java/include
/usr/lib/jvm/java/include
/usr/lib/jvm/java-6-sun/include
/usr/lib/jvm/java-1.5.0-sun/include
/usr/lib/jvm/java-6-sun-1.6.0.00/include # can this one be removed according to #8821 ? Alex
#/usr/lib/jvm/java-6-openjdk/include
/usr/local/share/java/include
/usr/lib/j2sdk1.4-sun/include
/usr/lib/j2sdk1.5-sun/include
/opt/sun-jdk-1.5.0.04/include
# Debian specific path for default JVM
#/usr/lib/jvm/default-java/include
# OpenBSD specific path for default JVM
/usr/local/jdk-1.7.0/include
/usr/local/jdk-1.6.0/include
/usr/lib/jvm/java-7-oracle/include
)
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.