Java 如何解决“找不到 JNI”,在 Raspberry Pi 上构建 OpenCV?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18529800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve "Could not find JNI", building OpenCV on Raspberry Pi?
提问by Dmitry Obukhov
I try to build opencv with Java on Raspberry Pi (Debian 4.6.3) and get every time an error from cmake: Could not find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH). I used this documentation (http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html#sbt-project-for-java-and-scala). I have been searching for solution in the Internet for a while. The suggestions were set JAVA_HOME variable, install ant, install python, add ${JAVA_HOME}/bin variable to the PATH variable, set JDK_HOME variable to my jdk1.8.0 home. Unfortunately, nothing has helped me yet. I tried everything, I even tried to completely remove opencv (2.4.6.1) from the Raspberry Pi, download another Version (2.4.6) and build it with cmake - nothing worked. I have two jre's on the Raspberry Pi: one (probably) preinstalled "Java-6-openjdk-armhf" and one, I installed by myself "Java Early Access" (jdk1.8.0 - speciffically for Raspbian with hardfloat). I tried to set JAVA_HOME to "/home/pi/java/jdk1.8.0" (where I installed "Java Early Access") and "/home/pi/java/jdk1.8.0/", The Problem seems to be that cmake cannot find jni.h file, which usually can be found in "JAVA_HOME/include/". I checked this file and I have it; if I type "ls $JAVA_HOME/include" in the shell, I get files with jni.h among them. So, I am out of ideas. Please, help me, if you know how to solve my Problem.
我尝试在 Raspberry Pi(Debian 4.6.3)上使用 Java 构建 opencv,并且每次从 cmake 中得到错误:找不到 JNI(缺少:JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)。我使用了这个文档(http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html#sbt-project-for-java-and-scala)。我一直在互联网上寻找解决方案一段时间。建议设置JAVA_HOME变量,安装ant,安装python,将${JAVA_HOME}/bin变量添加到PATH变量中,将JDK_HOME变量设置为我的jdk1.8.0 home。不幸的是,还没有什么能帮到我。我尝试了所有方法,甚至尝试从 Raspberry Pi 中完全删除 opencv (2.4.6.1),下载另一个版本 (2.4.6) 并使用 cmake 构建它 - 没有任何效果。我在 Raspberry Pi 上有两个 jre:一个(可能)预装了“Java-6-openjdk-armhf”,另一个是我自己安装的“Java Early Access”(jdk1.8.0 - 特别适用于带有硬浮点的 Raspbian)。我试图将 JAVA_HOME 设置为“/home/pi/java/jdk1.8.0”(我安装了“Java Early Access”)和“/home/pi/java/jdk1.8.0/”,问题似乎是cmake找不到jni.h文件,通常可以在“JAVA_HOME/include/”中找到。我检查了这个文件,我有它;如果我在 shell 中输入“ls $JAVA_HOME/include”,我会得到其中包含 jni.h 的文件。所以,我没有想法。如果您知道如何解决我的问题,请帮助我。
Thanks in advance!
提前致谢!
Dmitry
德米特里
回答by user2740142
I've finally found the solution of my Problem, so I answer it by myself. As it turned out, cmake checks for System variables of Administrator on Raspberry Pi, I, unfortunately, set JAVA_HOME and ANT_HOME only for my user (not administrator). It seems that if I change file /etc/Profile, the changes will not concern the Administrator and I didn't know that :-(
我终于找到了我的问题的解决方案,所以我自己回答了。事实证明,cmake 检查 Raspberry Pi 上管理员的系统变量,不幸的是,我仅为我的用户(不是管理员)设置了 JAVA_HOME 和 ANT_HOME。似乎如果我更改文件 /etc/Profile,更改将与管理员无关,我不知道:-(
So, after I set JAVA_HOME and ANT_HOME plus PATH for the Administrator, cmake has found ANT and JNI.
所以,在我为管理员设置了 JAVA_HOME 和 ANT_HOME 加上 PATH 之后,cmake 已经找到了 ANT 和 JNI。
Hope, it will help somebody!
希望,它会帮助某人!
Best regards,
此致,
Dmitry
德米特里
回答by Marco Ponzi
I had this problem on amazon EC2 and solved it with:
我在亚马逊 EC2 上遇到了这个问题,并通过以下方式解决了它:
sudo yum install java-1.7.0-openjdk-devel
须藤 yum 安装 java-1.7.0-openjdk-devel