13

我在 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 组件。我已经在“/usr/lib/jvm/jdk1.7.0_25”中手动安装了 Oracle Java 7 JDK,并使用“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)”可以正常工作。

感谢您的任何建议。

4

2 回答 2

28

您可以手动修改 FindJNI.cmake 以帮助它找到您安装的 JDK。请参阅此要点:

https://gist.github.com/emchristiansen/6845954

很遗憾这个脚本没有更新,但也许并不奇怪,因为 CMake 是一场灾难。

编辑:更直接的解决方案是JAVA_HOME正确设置。安装 OpenJDK 7 后,我将其设置为:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

于 2013-10-05T21:02:04.273 回答
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 和 default 相关行,因为它们与 oracle 安装冲突。

于 2014-01-27T14:42:50.753 回答