Q:

Run jar file with external and local library

I try to write a program with java and I want every body can run the program without any setting in their system.My program use RXTX-2.1.7 library. I add rxtx-2.1.7.jar to my program and I don't add it to my jre. I don't set path in Environment Variables.So I build my project with NetBeans IDE 8.0. IDE make jar file and in same folder copy rxtx library. Then I made a batch file with this command java -jar MainFrame.jar. But when I run the batch file I see this error:
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1119)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
    at pkg.MainFrame.process(MainFrame.java:82)
    at pkg.MainFrame.access$100(MainFrame.java:12)
    at pkg.MainFrame$1.run(MainFrame.java:71)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

What should I do?

A:

It seems you forgot to add RXTX's shared library (.DLL, .so, .dylib) in the lib path. Try adding -Djava.library.path="\path\to\rxtx\dll"

