简体   繁体   English

OpenCV Java项目在Eclipse中运行,但不在命令行中运行

[英]OpenCV java project runs in Eclipse but not in Command line

I downloaded OpenCV for Java and added the jar and libraries to the project in Eclipse and it works fine. 我下载了Java的OpenCV,并将jar和库添加到Eclipse中的项目中,并且工作正常。

But when I try to run the .class file where my main(String args[]) is, it throws 但是当我尝试运行我的main(String args[])所在的.class文件时,它将抛出

> java MainActivity 1 5 8
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
    at HoleFiller.<init>(HoleFiller.java:29)
    at MainActivity._fixHole(MainActivity.java:100)
    at MainActivity._getImageNames(MainActivity.java:92)
    at MainActivity._authArgTypes(MainActivity.java:66)
    at MainActivity.main(MainActivity.java:17)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

It crashes on this line 它在这条线上崩溃

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Is there any way to include the .jar file in the project so it will run from the command line? 有什么方法可以在项目中包含.jar文件,以便它可以从命令行运行?

Thanks in advance 提前致谢

When you run within Eclipse, then the IDE will automatically handle the dependencies, but when you run from the commadnd line, then you need you to handle it your self. 当您在Eclipse中运行时,IDE将自动处理依赖关系,但是当您从commadnd行运行时,则需要您自己处理它。

Follow these commands to do so: 请按照以下命令进行操作:

  1. When compiling: 编译时:

javac -cp path/to/opencv.jar YourProgram.java javac -cp path / to / opencv.jar YourProgram.java

  1. When running: 运行时:

java -cp path/to/opencv.jar:. java -cp path / to / opencv.jar:。 -Djava.library.path=path/to/opencv.dll YourProgram -Djava.library.path =路径/到/opencv.dll YourProgram

And you can add the .dll path to the system path, then it will automatically get access to it. 您可以将.dll路径添加到系统路径,然后它将自动获得对其的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM