java - IntelliJ does not find native libraries for OpenCV when adding jar as a dependency for Play project -
i working on play 2.1 project, in requests web-service handle downloading user-supplied images, re-sizing , re-cropping them, , filtering out known bad photos (for example, don't want users upload company logos). trying use opencv handle back-end work, can't seem intellij add opencv jar in way works java project.
i've been able build opencv source, without issue. left me following folder: /home/charles/opencv/release
inside folder, have 3 files of interest:
- bin/opencv-246.jar
- lib/cv2.so
- lib/libopencv_java246.so
if try add jar file intellij new java library, seemingly finds classes/methods, , can write code using auto-complete. can click on respective classes or methods, , brings me right files.
however, when try run play project, error:
[info] loading project definition /home/charles/github/imageproject [info] set current project imageproject (in build file:/home/charles/github/imageproject/) --- (running application sbt, auto-reloading enabled) --- [info] play - listening http on /0:0:0:0:0:0:0:0:9000 server started, use alt+d stop [info] compiling 1 java source /home/charles/github/imageproject/target/scala-2.10/classes... [error] /home/charles/github/imageproject/app/controllers/application.java:7: error: package org.opencv.core not exist [error] import org.opencv.core.core; [error] ^
i've tried adding copy of jar file directly project (so putting opencv-246.jar imageproject/lib), , adding java library location instead. leaves me different error:
java.lang.unsatisfiedlinkerror: no opencv_java246 in java.library.path
i suspect part of problem may related native libraries java opencv wrapper uses (file 2 or 3 above). in eclipse, when add jar file, can explicitly set native library location, makes opencv work fine. i've read suggestions of using fix problem:
-djava.library.path=/home/charles/opencv/release/lib
but doesn't seem work (though maybe i'm setting in wrong place? i've tried setting jvm parameter in run config project, , in ide settings, neither seem used or respected).
note: clarify again, play2 project, not android project. there seems android-specific out there, isn't relevant in case.
this feels should rather straight forward thing, i've been spending several days trying find answer @ point, , still have nothing. ideas?
additional details: tried following "running sbt samples" of opencv documentation here: http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html
and similar error:
charles@charles-virtualbox:~/javasample$ sbt run [info] loading project definition /home/charles/javasample/project [info] set current project javasample (in build file:/home/charles/javasample/) [info] compiling 1 java source /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 @ java.lang.classloader.loadlibrary(classloader.java:1856) @ java.lang.runtime.loadlibrary0(runtime.java:845) @ java.lang.system.loadlibrary(system.java:1084) @ helloopencv.main(helloopencv.java:47) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:601) [trace] stack trace suppressed: run last compile:run full output. java.lang.runtimeexception: nonzero exit code: 1 @ scala.sys.package$.error(package.scala:27) [trace] stack trace suppressed: run last compile:run full output. [error] (compile:run) nonzero exit code: 1 [error] total time: 2 s, completed jul 17, 2013 5:11:39 pm
when want use opencv or other native libraries on playframework, must run application "play start" command, not "play run".
"play run" command starts application in development mode , "play start" command starts in production mode. don't know every difference between them 1 obvious thing ,
only when use "play start", new jvm application launched , loads native libraries specified system.load("/absolute/path/to/your/so/or/jnilib/inosx/not/dylib/filename.jnilib");
how load native lib following.
create global.java has empty package name. (refer this link )
public class global extends globalsettings { @override public void beforestart(application app) { // todo auto-generated method stub super.beforestart(app); string libopencv_java = "/users/yoonjechoi/git/myfirstapp/target/native_libraries/64bits/libopencv_java246.jnilib"; system.load(libopencv_java); } }
then can use classes of opencv in play application's controllers.
system.loadlibrary("opencv_java246") doesn't works. don't know why. don't have time dig why. -_-;
please give hints if know why.
Comments
Post a Comment