Netbeans:构建后找不到库

时间:2011-02-05 00:04:35

标签: java netbeans

这是我的系统信息:

IDE:NetBeans 6.9 操作系统:Ubuntu 10.10

我正在使用java和v4l4j(http://code.google.com/p/v4l4j/)编写程序,该程序从网络摄像头捕获帧并以特定方式处理它们。程序启动时,会出现一个对话框,询问捕获设备。选择设备后,将启动查看器。此时,使用网络摄像头类。

每当我使用netbean的运行功能运行程序时,一切都很好。它100%工作。但是,当我复制jar和运行到另一个文件夹以进行分发所需的所有文件时,它根本不起作用。一旦选择的GUI完成并且启动了查看器,程序就会因此错误而崩溃:

Cant load v4l4j JNI library
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no v4l4j in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at au.edu.jcu.v4l4j.VideoDevice.<clinit>(Unknown Source)
at programName.webcam.initVideoDevice(webcam.java:49)
at programName.webcam.<init>(webcam.java:32)
at programName.Main.initCamera(Main.java:164)
at programName.Main.initCamera(Main.java:184)
at programName.Main.<init>(Main.java:82)
at programName.openingWindow$checker.actionPerformed(openingWindow.java:126)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

同样,这只发生在netbeans的一边耗尽时。我将lib文件夹复制到与jar相同的目录中。基本上,这就是我所拥有的:

directory root/
    program.jar
    data/
        images/
        settings/
    lib/
        v4l4j.jar

NetBEans dist文件夹中的所有文件都已复制,我拥有所有必需的资源文件,例如图像和设置文件。出于某种原因,直到最近,当我开始收到此错误时,这种情况一直很好。

另外,这是错误引用的函数。这是该类使用缺少的库的第一个结果。

private void initVideoDevice() throws Exception {
    vd = new VideoDevice(path);
    fg = vd.getJPEGFrameGrabber((int)resolution.getWidth(), (int)resolution.getHeight(), 0, standard, quality);
}

2 个答案:

答案 0 :(得分:1)

尝试按如下方式运行程序:

java -Djava.library.path=/absolute/path/to/lib/folder/containing/your/library -jar program.jar

答案 1 :(得分:1)

正如BuHHu-nyx指出的那样,这是因为找不到v4l4j J​​NI共享库(libv4l4j.so)。您必须使用-D参数告诉JVM在哪里找到此库(及其依赖项),除非您已尝试使用libv4l4j.so NOT v4l4j.jar的完整路径。 你安装了v4l4j吗?如果是,libv4l4j应该在/ usr / lib / jni。