title: IntelliJ does not find native libraries for OpenCV when adding jar as a dependency for Play project
body: <p>I am currently working on a Play 2.1 project, in which requests to the web-service will handle downloading user-supplied images, re-sizing and re-cropping them, and also filtering out known bad photos (for example, we don't want users to upload company logos).  We are trying to use OpenCV to handle the back-end work, but I can't seem to get IntelliJ to add the OpenCV jar in a way that works with the java project.</p>
  
  <p>I've been able to build OpenCV from source, without issue.  This left me with the following folder:
  /home/charles/opencv/release</p>
  
  <p>Inside this folder, I have three files of interest:</p>
  
  <ol>
  <li>bin/opencv-246.jar</li>
  <li>lib/cv2.so</li>
  <li>lib/libopencv_java246.so</li>
  </ol>
  
  <p>If I try to add the jar file to IntelliJ as a new Java library, it seemingly finds all the classes/methods, and I can write code using the auto-complete.  I can also click on the respective classes or methods, and it brings me to the right files.</p>
  
  <p>However, when I try to run the Play project, I get this error:</p>
  
  <pre><code>[info] Loading project definition from /home/charles/Github/ImageProject
  [info] Set current project to ImageProject (in build file:/home/charles/Github/ImageProject/)
  
  --- (Running the application from SBT, auto-reloading is enabled) ---
  
  [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
  
  Server started, use Alt+D to stop
  
  [info] Compiling 1 Java source to /home/charles/Github/ImageProject/target/scala-2.10/classes...
  [error] /home/charles/Github/ImageProject/app/controllers/Application.java:7: error: package org.opencv.core does not exist
  [error] import org.opencv.core.Core;
  [error]                       ^
  </code></pre>
  
  <p>I've also tried adding a copy of the jar file directly into the project (so putting opencv-246.jar into ImageProject/lib), and then adding the java library from that location instead.  But that just leaves me with a different error:</p>
  
  <pre><code>java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path
  </code></pre>
  
  <p>I suspect part of the problem may be related to the native libraries that the Java OpenCV wrapper uses (file 2 or 3 above).  In Eclipse, when you add a jar file, you can explicitly set the native library location, which makes OpenCV work fine.  I've read suggestions of using this to fix the problem:</p>
  
  <pre><code>-Djava.library.path=/home/charles/opencv/release/lib
  </code></pre>
  
  <p>But that doesn't seem to work (though maybe I'm setting it in the wrong place?  I've tried setting it as a JVM parameter in the run config for the project, and in the IDE settings, but neither seem to be used or respected).</p>
  
  <p>Note: Just to clarify again, this is a Play2 project, not an Android project.  There seems to be some Android-specific help out there, that isn't relevant in this case.</p>
  
  <p>This feels like it should be a rather straight forward thing, but I've been spending several days trying to find an answer at this point, and still have nothing.  Any ideas?</p>
  
  <p><strong>Additional details:</strong>
  I also tried following the "Running SBT samples" of the OpenCV documentation here:
  <a href="http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html" rel="nofollow">http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html</a></p>
  
  <p>And I also get a similar error:</p>
  
  <pre><code>charles@charles-VirtualBox:~/JavaSample$ sbt run
  [info] Loading project definition from /home/charles/JavaSample/project
  [info] Set current project to JavaSample (in build file:/home/charles/JavaSample/)
  [info] Compiling 1 Java source to /home/charles/JavaSample/target/scala-2.10/classes...
  [info] Running HelloOpenCV 
  Hello, OpenCV
  [error] (run-main) java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path
  java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
      at java.lang.Runtime.loadLibrary0(Runtime.java:845)
      at java.lang.System.loadLibrary(System.java:1084)
      at HelloOpenCV.main(HelloOpenCV.java:47)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
  [trace] Stack trace suppressed: run last compile:run for the full output.
  java.lang.RuntimeException: Nonzero exit code: 1
      at scala.sys.package$.error(package.scala:27)
  [trace] Stack trace suppressed: run last compile:run for the full output.
  [error] (compile:run) Nonzero exit code: 1
  [error] Total time: 2 s, completed Jul 17, 2013 5:11:39 PM
  </code></pre>