How to add OpenCV lib to Dynamic Web Project

I am currently creating a Java web project that uses Opencv to detect similar images. But when I run, I always get this error

java.lang.UnsatisfiedLinkError: expecting an absolute library path: opencv_java249 java.lang.Runtime.load0 (Runtime.java:806) java.lang.System.load (System.java:1086) com.hadoop.DriverServlet.doPost (DriverServlet. java: 25) javax.servlet.http.HttpServlet.service (HttpServlet.java:650) javax.servlet.http.HttpServlet.service (HttpServlet.java:731) org.apache.tomcat.websocket.server.WsFilter.doil WsFilter.java:52)

I am also looking for this problem, but still cannot find a solution to my case. even i try this http://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/ to add the path to opencv-249 to java.library jar in eclipse, but still could not solve it.

Can anybody help me? Thanks in advance.

+8
java opencv
source share
2 answers

To work with opencv you need a jar file and a binary file. The JAR file can simply be added by the local maven repository or by any other option.

Binary file to be added and downloaded manually. Something like that:

private static void addLibraryPath(String pathToAdd) throws Exception{ final Field usrPathsField = ClassLoader.class.getDeclaredField("usr_paths"); usrPathsField.setAccessible(true); //get array of paths final String[] paths = (String[])usrPathsField.get(null); //check if the path to add is already present for(String path : paths) { if(path.equals(pathToAdd)) { return; } } //add the new path final String[] newPaths = Arrays.copyOf(paths, paths.length + 1); newPaths[newPaths.length-1] = pathToAdd; usrPathsField.set(null, newPaths); } public void init() { String pathToOpenCvDll = "c:\\opencv\\"; //linux path works too try { addLibraryPath(pathToOpenCvDll); System.loadLibrary("opencv_java320"); } catch (Exception ignored) { } } } 
+2
source share

For a web project, the jar library file must be in the WEB-INF / lib directory.

Also make sure the banks in the directory are in the class path

0
source share

All Articles