title: Installing OpenCV on Raspbian for Java, "Could not FindJNI"
body: <p>I'm trying to install OpenCV on Raspbian so that I can deploy my Java code onto the RPi. However, having cmake find JNI is proving to be an irksome task. One question that was answered here noted that the administrator needed to have JAVA_HOME set as well, not just the user. So I set it in /etc/environment as well as the prior setting in .bashrc. </p>
  
  <p><a href="https://stackoverflow.com/questions/18529800/how-to-resolve-could-not-find-jni-building-opencv-on-raspberry-pi">How to resolve &quot;Could not find JNI&quot;, building OpenCV on Raspberry Pi?</a></p>
  
  <p>However, cmake still cannot find JNI, even after I updated it to find the Include directories as noted in the following;</p>
  
  <p><a href="https://stackoverflow.com/questions/17636166/cmake-find-packagejni-not-work-in-ubuntu-12-04-amd64">cmake find_package(JNI) not work in Ubuntu 12.04 amd64</a></p>
  
  <p>I've tried many different combinations, including the Java installation and environment setting at, though it unzips java in /opt/java and recommends setting JAVA_HOME to there;</p>
  
  <p><a href="http://elinux.org/RPi_Java_JDK_Installation" rel="nofollow noreferrer">http://elinux.org/RPi_Java_JDK_Installation</a></p>
  
  <p>Pertinent FindJNI.cmake lines include;</p>
  
  <pre><code>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/jdk-7-oracle-armhf/include  &lt;-- Added by me
  </code></pre>
  
  <p>and </p>
  
  <pre><code>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/jdk-7-oracle-armhf
    /usr/lib/jvm/jdk-7-oracle-armhf/lib
    /usr/lib/jvm/jdk-7-oracle-armhf/lib/{libarch}
    /usr/lib/jvm/jdk-7-oracle-armhf/{libarch}
  </code></pre>
  
  <p>Pertinent OpenCV install script lines include;</p>
  
  <pre><code>cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=OFF  -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON WITH_QT=ON -D WITH_OPENGL=ON ..
  make -j 8
  sudo make install
  </code></pre>
  
  <p>Cmake output includes;</p>
  
  <blockquote>
    <p>-- Could NOT find JNI (missing:  JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY)<br>
    System is unknown to cmake, create: Platform/error pid:6186,
    boost::interprocess::bad_alloc Linux to use this system, please send
    your config file to cmake@www.cmake.org so</p>
  </blockquote>
  
  <p>I'm at a loss for any more clues to load OpenCV on Raspbian where Java can be used - what else do I need to do?</p>