java 如何为 VLCJ 添加或安装本机 x64 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14319656/
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
How do I add or install the native x64 libraries for VLCJ?
提问by wutang
I am trying make a messenger program in Java that has a video player in it, so I'm using vlcj. But I receive this error:
我正在尝试用 Java 制作一个带有视频播放器的信使程序,所以我使用的是 vlcj。但我收到此错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
Unable to load library 'libvlc':
The specified module could not be found.
线程“main”中的异常 java.lang.UnsatisfiedLinkError:
无法加载库“libvlc”:
找不到指定的模块。
I have followed the tutorials from here, but I still get this error. This is the only error that I get.
我已按照此处的教程进行操作,但仍然出现此错误。这是我得到的唯一错误。
I'm running on Windows 7 x64 Ultimate with a x64 VLC. I'm coding using the latest Eclipse version.
我在带有 x64 VLC 的 Windows 7 x64 Ultimate 上运行。我正在使用最新的 Eclipse 版本进行编码。
Can anyone guide me step-by-step on how to fix this?
谁能指导我一步一步地解决这个问题?
回答by Imrank
you have to add "libvlc" and "libvlccore" dll path in your application. these will be present into your vlc installation folder. you can add following line of code to get it working.
您必须在应用程序中添加“libvlc”和“libvlccore”dll 路径。这些将出现在您的 vlc 安装文件夹中。您可以添加以下代码行以使其正常工作。
NativeLibrary.addSearchPath("libvlc", "C:/VideoLAN/VLC");
here "C:/VideoLAN/VLC" is installation folder of vlc.
这里“C:/VideoLAN/VLC”是vlc的安装文件夹。
回答by Carsten Engelke
Make sure you are using either a straight x64 or x32 environment. This means:
确保您使用的是直接的 x64 或 x32 环境。这意味着:
- Windows x64 (obviously)
- Java JRE x64 (do not install a second x32 JRE)
- Java JDK x64
- VLC x64
- Windows x64(显然)
- Java JRE x64(不要安装第二个 x32 JRE)
- Java JDK x64
- VLC x64
Now you should be fine.
现在你应该没事了。
回答by jaguililla
I read the vlcjinstructions you posted.
我阅读了您发布的vlcj说明。
It seems the vlcjlibrary is using JNA and you can setup the library search path using the NativeLibraryclass as is stated in the check program:
似乎vlcj库正在使用 JNA,您可以使用NativeLibrary类设置库搜索路径, 如检查程序中所述:
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
public class Tutorial1A {
public static void main(String[] args) {
String vlcHome = "dir/with/dlls"; // Dir with vlc.dll and vlccore.dll
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), vlcHome
);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
}
}
Yo can try to run that code and check if it completes without exceptions.
您可以尝试运行该代码并检查它是否无异常地完成。
vlcjinstructions also points out that the architecture of the JRE is relevant; you should check your JRE architecture by typing:
vlcj指令还指出JRE的架构是相关的;您应该通过键入以下内容来检查您的 JRE 架构:
java -version
The JRE architecture should match the VLC one (maybe you can check the VLC architecture in the About dialog). Both should be equal (32b or 64b).
JRE 架构应该与 VLC 匹配(也许您可以在“关于”对话框中查看 VLC 架构)。两者应该相等(32b 或 64b)。
However, it is strange that the error message refers to libvlcinstead vlcor vlccorebeing executed in Windows.
但是,奇怪的是,错误消息指的是libvlc而不是在 Windows 中执行的vlc或vlccore。
Anyway, if adding the VLC path to the search path using NativeLibrarydon't work and the JRE architecture matches the VLC one, you can add the code you are using to try to find out more.
无论如何,如果使用NativeLibrary将 VLC 路径添加到搜索路径不起作用并且 JRE 架构与 VLC 架构匹配,您可以添加您正在使用的代码以尝试找出更多信息。
回答by sorifiend
This is how you load the vlc libraries using JNA:
这是使用 JNA 加载 vlc 库的方式:
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "Path to native library");
For my program I have the vlc "libvlc.dll" and "vlccore.dll" located in a sub-folder lib/VLC/
so I load the files relative to my "program.jar" using System.getProperty("user.dir")
and adding the path to the end:
对于我的程序,我将 vlc“libvlc.dll”和“vlccore.dll”放在一个子文件夹中,lib/VLC/
因此我使用System.getProperty("user.dir")
并添加路径来加载与我的“program.jar”相关的文件:
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), System.getProperty("user.dir") + "/lib/VLC");
If you want to load the library from the default VLC install path in windows 7 you can do it as follows:
如果您想从 Windows 7 中的默认 VLC 安装路径加载库,您可以按如下方式进行:
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:/Program Files (x86)/VideoLAN/VLC");
Edit: If you run this code from within eclipse it will not work, unless you specify an absolute path to the VLC library files. If you want to test a relative path then first build the jar file and place it in the correct folder relative to the VLC library files.
编辑:如果您从 eclipse 中运行此代码,它将不起作用,除非您指定 VLC 库文件的绝对路径。如果要测试相对路径,则首先构建 jar 文件并将其放置在相对于 VLC 库文件的正确文件夹中。
回答by pap
As the error indicates, the JVM is attempting to load the native library "libvlc.dll", but is unable to locate it.
如错误所示,JVM 正在尝试加载本机库“libvlc.dll”,但无法找到它。
Either place the dll in the .../jre/bin directory in your java install, or use the java.library.path
property to point to it's location.
要么将 dll 放在 java 安装中的 .../jre/bin 目录中,要么使用该java.library.path
属性指向它的位置。
See also How to add native library to "java.library.path" with Eclipse launch (instead of overriding it)
回答by BaiJiFeiLong
cd src/main/resources/
cp -r /Applications/VLC.app/Contents/MacOS/lib darwin
rm darwin/*.*.*
cd darwin
install_name_tool -add_rpath @loader_path libvlc.dylib
mkdir vlc
cp -r /Applications/VLC.app/Contents/MacOS/plugins vlc/plugins
This is the macOS version. Maybe help you.
这是 macOS 版本。也许能帮到你。
├── kotlin
│?? └── App.kt
└── resources
└── darwin
├── libvlc.dylib
├── libvlccore.dylib
└── vlc
└── plugins
├── liba52_plugin.dylib
├── libaccess_concat_plugin.dylib
├── libaccess_imem_plugin.dylib
├── libaccess_mms_plugin.dylib
回答by John Deverall
Set the path with the jna.library.path
system property. A working example of this technique can be found at:
使用jna.library.path
系统属性设置路径。可以在以下位置找到此技术的工作示例:
in the public static void main(String[] args)
method.
在public static void main(String[] args)
方法。
This code is likely to be updated soon which will destroy the above link but you can always use version control to go back to the date I posted this and take a look at the code.
这段代码很可能很快就会更新,这会破坏上面的链接,但你总是可以使用版本控制回到我发布这篇文章的日期并查看代码。