“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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 08:23:38  来源:igfitidea点击:

"Java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path"

javaopencvjenkins

提问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) 应该完全像这样。

enter image description here

在此处输入图片说明

回答by Long Nguyen

If you're using IntelliJ IDEA you should add OpenCV library as Native Library Location.

如果您使用 IntelliJ IDEA,您应该添加 OpenCV 库作为本机库位置。

  1. Go to File> Project Structure
  2. From side panel select Modulesand then select the Dependenciestab
  3. Click the +icon on the bottom to add a dependency. Then select the Add JARS or directoriesoption.
  4. 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 click Open.

    ※ If you can not find that jar file. I predict that you forgot build OpenCV repo. Reference this introduction

  5. 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

  6. Then click on the +icon to add the Native Library Location.
  7. And then browse to the location where you installed OpenCV and select build/lib(in somecase it will be build/java/x64). Now click Open.
  1. 前往File>Project Structure
  2. 从侧面板选择Modules然后选择Dependencies选项卡
  3. 单击+底部的图标以添加依赖项。然后选择Add JARS or directories选项。
  4. 然后浏览到安装 OpenCV 的路径并选择build/bin/opencv-***.jar(或在某些情况下为 build/java/opencv-***.jar)并单击Open

    ※如果找不到那个jar文件。我预测您忘记构建 OpenCV 存储库。参考这个介绍

  5. 它将在窗口中显示为依赖项。现在,我们还必须添加本地库位置。为此,双击 opencv-***.jar

  6. 然后单击该+图标以添加本机库位置。
  7. 然后浏览到安装 OpenCV 的位置并选择build/lib(在某些情况下它会是build/java/x64)。现在点击Open

enter image description here

在此处输入图片说明

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.pathin VM option like -Djava.library.path={PATH_T0_LIBRARY}

PS:您也可以添加java.library.pathVM选项,如-Djava.library.path={PATH_T0_LIBRARY}

enter image description here

在此处输入图片说明