Netbeans: library not found after build
Here is my system info:
IDE: NetBeans 6.9 OS: Ubuntu 10.10
I'm writing a program using java and v4l4j (http://code.google.com/p/v4l4j/) which captures frames from webcams and processes them in a specific way. When the program starts a dialog box appears to ask for the capture device. Once the device is selected a viewer is started. At this point, the webcam class is used.
Whenever I run the program with netbean's run functionality everything is fine. It works 100%. However, when I copy the jar and all of the files needed to run into a different folder for distribution it simply does not work. As soon as the select GUI finishes and the viewer is launched the program will crash with this error:
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)
Again, this only occurs when running out side of netbeans. I copied over the lib folder into the same directory as the jar. Here's, basically, what I have:
directory root/
program.jar
data/
images/
settings/
lib/
v4l4j.jar
All the files in the NetBEans dist folder were copied a开发者_如何学JAVAnd I have all the required resource files, such as images and settings files. For some reason, this used to work perfectly until just recently, when I started getting this error.
Also, here's the function which the error references. It's the first tiem that the class uses the missing library.
private void initVideoDevice() throws Exception {
vd = new VideoDevice(path);
fg = vd.getJPEGFrameGrabber((int)resolution.getWidth(), (int)resolution.getHeight(), 0, standard, quality);
}
As BuHHu-nyx pointed out, this happens because the v4l4j JNI shared library (libv4l4j.so) cannot be found. You must tell the JVM where to find this library (and its dependency) using the -D argument, EXCEPT that you must use the full path to libv4l4j.so NOT v4l4j.jar as you have tried. Have you installed v4l4j ? If yes, libv4l4j should be in /usr/lib/jni.
Try to run your program as follows:
java -Djava.library.path=/absolute/path/to/lib/folder/containing/your/library -jar program.jar
精彩评论