java 使用使用程序的想法将dll库添加到java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3961001/
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-10-30 04:10:16  来源:igfitidea点击:

adding dll library to java using idea for using a program

javaintellij-ideavlcjvlc

提问by sajad

I am trying to add and use a program called JVLC to my program. I downloaded a zip file that contains a jar file(jvlc.jar) for java interface and 2 dll files (jvlc.dll , libvlc.dll) and a folder that contains many dll files. when I run my program an UnsatisfiedLinkError occurs. I used this code to add those 2 dll files to my project.

我正在尝试在我的程序中添加和使用一个名为 JVLC 的程序。我下载了一个 zip 文件,其中包含一个用于 java 接口的 jar 文件(jvlc.jar)和 2 个 dll 文件(jvlc.dll、libvlc.dll)以及一个包含许多 dll 文件的文件夹。当我运行我的程序时,会发生 UnsatisfiedLinkError。我使用此代码将这 2 个 dll 文件添加到我的项目中。

System.loadLibrary("C:\Users\sajad\Documents\Downloads\Compressed\JVLC\jvlc.dll");
System.loadLibrary("C:\Users\sajad\Documents\Downloads\Compressed\JVLC\libvlc.dll");

but still there is error:

但仍然有错误:

UnsatisfiedLinkError: Directory separator should not appear in library name

UnsatisfiedLinkError:目录分隔符不应出现在库名称中

Is it necessary to add all folder to library paths? If yes how?

是否有必要将所有文件夹添加到库路径?如果是如何?

please guide me.

请指导我。

回答by Buhake Sindi

The System.loadLibrarymethod loads a libary based on a library name (libName, without extension) and notthrough file name. Example, Java comes with a zip.dll / zip.so (Linux) that is used when we use the Zip Deflater/Inflater classes for zip files.

System.loadLibrary方法根据库名(libName,不带扩展名)而不是通过文件名加载库。例如,Java 附带了一个 zip.dll / zip.so (Linux),当我们将 Zip Deflater/Inflater 类用于 zip 文件时会使用它。

If you want to use specify a dll file name, use the System.load(String filename)method otherwise, register your DLL in a java lib path.

如果要使用指定 dll 文件名,请使用其他System.load(String filename)方法,在 java lib 路径中注册您的 DLL。

An example can be found here.

可以在此处找到示例。



For your example, please do this:

对于您的示例,请执行以下操作:

//Your code....
System.loadLibrary("C:\Users\sajad\Documents\Downloads\Compressed\JVLC\jvlc.dll");
System.loadLibrary("C:\Users\sajad\Documents\Downloads\Compressed\JVLC\libvlc.dll");

//Replace with this...
System.load("C:\Users\sajad\Documents\Downloads\Compressed\JVLC\jvlc.dll");
System.load("C:\Users\sajad\Documents\Downloads\Compressed\JVLC\libvlc.dll");

回答by Bruno

According to this tutorial:

根据本教程

  • You need to set LD_LIBRARY_PATH(on Linux/Unix) or PATH(Windows) include the directory where the libraries are.
  • You don't need the .dllsuffix.
  • 您需要设置LD_LIBRARY_PATH(在 Linux/Unix 上)或PATH(Windows)包含库所在的目录。
  • 你不需要.dll后缀。