我在Ubuntu 12.04 amd64上使用cmake 2.8.7。我系统中安装的OpenJDK JRE组件如下所示:
$ 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)
但是,我没有使用OpenJDK JRE组件。我手动安装了Oracle Java 7 JDK 在“/usr/lib/jvm/jdk1.7.0_25”中并使用“update-alternatives”将“java”指向我安装的Oracle Java 7 JDK。我没有设置任何“JAVA_HOME”,“JAVA_BIN”,“CLASSPATH”环境变量和手动安装的Oracle Java 7 JDK似乎在Eclipse 4.3中正常工作。
问题是当我在cmake中使用“find_package(JNI)”并使用“message()”函数来显示JNI变量时,我得到以下结果:
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
“find_package(JNI)”似乎可以找到一些与OpenJDK JRE相关的Java组件,但找不到“update-alternatives”指向的当前Oracle Java 7 JDK组件。
我想知道“FindJNI.cmake”文件中是否有任何错误以及我在Oracle Java 7 JDK设置中遗漏的错误,以便cmake“find_package(JNI)”可以正常工作。
感谢您的任何建议。
答案 0 :(得分:26)
您可以手动修改FindJNI.cmake以帮助它找到已安装的JDK。 看到这个要点:
https://gist.github.com/emchristiansen/6845954
令人遗憾的是,这个剧本还没有更新,但也许并不奇怪,因为CMake是一场灾难。
编辑:更直接的解决方案是正确设置JAVA_HOME
。
安装OpenJDK 7后,我将其设置为:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
答案 1 :(得分:4)
如果您的系统上安装了oracle jdk 7,就像我的情况一样,您可能会在构建opencv时遇到问题。为了解决这些问题,我必须编辑/usr/share/cmake-2.8/Modules/FindJNI.cmake文件。在这个文件中,我注释掉了引用openjdk和default的行,并添加了oracle jdk 7的引用,如下所示。
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
)
并在脚本查找的部分中包含库...
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
)
然后我按照确切的说明为android构建了openCV。
我必须注释掉openjdk和默认相关的行,因为它们与oracle安装相冲突。