“Java.lang.UnsatisfiedLinkError:java.library.path 中没有 opencv_java320”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44884648/
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
"Java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path"
提问by viktors89
I have a selenium test that when it finishes makes some operations with OpenCV. With IntelliJ IDEA it works fine, the operations process correctly, but when I try to execute through command line (for Jenkins use in the near future), I get the error mentioned above:
我有一个硒测试,当它完成时使用 OpenCV 进行一些操作。使用 IntelliJ IDEA 它工作正常,操作过程正确,但是当我尝试通过命令行执行时(供 Jenkins 在不久的将来使用),我收到上面提到的错误:
"Java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path"
“Java.lang.UnsatisfiedLinkError:java.library.path 中没有 opencv_java320”
I read the other questions on here and I've set up the java.library.path to the path where the jar and dll files are, but the error still comes up and I'm running out of ideas.
我在这里阅读了其他问题,我已经将 java.library.path 设置为 jar 和 dll 文件所在的路径,但错误仍然出现,我的想法已经用完了。
Could you please help me?
请你帮助我好吗?
Thanks!
谢谢!
采纳答案by SubOptimal
Please find below a working snippet. Which you need to adapt to your needs.
请在下面找到一个工作片段。您需要适应您的需求。
assume following file structure
假设以下文件结构
libs\opencv_java320.dll
pom.xml
src\test\java\sub\optimal\OpenCVTest.java
pom.xml- the part for the testing
pom.xml- 测试部分
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>-Djava.library.path=${project.basedir}/libs/</argLine>
</configuration>
</plugin>
</plugins>
</build>
sub\optimal\OpenCVTest.java
子\最佳\ OpenCVTest.java
package sub.optimal;
import org.junit.Test;
public class OpenCVTest {
@Test
public void someOpenCVTest() {
System.out.printf("java.library.path: %s%n",
System.getProperty("java.library.path"));
System.loadLibrary("opencv_java320");
}
}
run the test
运行测试
mvn compile test
output
输出
...
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running sub.optimal.OpenCVTest
java.library.path: X:\develop\opencv-demo/libs/
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: ...
...
回答by VK321
This worked for me. I am using intellij on mac
这对我有用。我在 mac 上使用 intellij
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Test {
public static void main(String[] args){
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME); - REMOVE THIS
nu.pattern.OpenCV.loadShared(); //add this
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
}
}
And dependency
和依赖
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>
回答by Ankit Gupta
If you are using STS/Eclipse or any IDE then follow the steps to getting solve your unsatisfiedlinkerror-no-opencv-java320error.
如果您使用的是 STS/Eclipse 或任何 IDE,请按照以下步骤解决您的 unsatisfiedlinkerror-no-opencv-java320错误。
Window -> Preferences -> User Libraries -> New -> create new Library Like attached Image
窗口 -> 首选项 -> 用户库 -> 新建 -> 像附加图像一样创建新库
Note:- Jar location and Native Library Location (opencv/build/java/x64) should be exactly like this while creating the new library.
注意:- 在创建新库时,Jar 位置和本机库位置 (opencv/build/java/x64) 应该完全像这样。
回答by Long Nguyen
If you're using IntelliJ IDEA you should add OpenCV library as Native Library Location.
如果您使用 IntelliJ IDEA,您应该添加 OpenCV 库作为本机库位置。
- Go to
File
>Project Structure
- From side panel select
Modules
and then select theDependencies
tab - Click the
+
icon on the bottom to add a dependency. Then select theAdd JARS or directories
option. Then browse to the path where you installed the OpenCV and select
build/bin/opencv-***.jar
(or build/java/opencv-***.jar in some case) and clickOpen
.※ If you can not find that jar file. I predict that you forgot build OpenCV repo. Reference this introduction
It will be shown as dependency in the window. Now, we also have to add the Native Library Location. To do that, double click on the opencv-***.jar
- Then click on the
+
icon to add the Native Library Location. - And then browse to the location where you installed OpenCV and select
build/lib
(in somecase it will bebuild/java/x64
). Now clickOpen
.
- 前往
File
>Project Structure
- 从侧面板选择
Modules
然后选择Dependencies
选项卡 - 单击
+
底部的图标以添加依赖项。然后选择Add JARS or directories
选项。 然后浏览到安装 OpenCV 的路径并选择
build/bin/opencv-***.jar
(或在某些情况下为 build/java/opencv-***.jar)并单击Open
。※如果找不到那个jar文件。我预测您忘记构建 OpenCV 存储库。参考这个介绍
它将在窗口中显示为依赖项。现在,我们还必须添加本地库位置。为此,双击 opencv-***.jar
- 然后单击该
+
图标以添加本机库位置。 - 然后浏览到安装 OpenCV 的位置并选择
build/lib
(在某些情况下它会是build/java/x64
)。现在点击Open
。
Now, you can use System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
to load library as expected
现在,您可以使用System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
按预期加载库
Reference: How to set-up OpenCV in IntelliJ IDEAof Aadam
参考:如何在Aadam的IntelliJ IDEA中设置OpenCV
PS: You also can add java.library.path
in VM option like -Djava.library.path={PATH_T0_LIBRARY}
PS:您也可以添加java.library.path
VM选项,如-Djava.library.path={PATH_T0_LIBRARY}