异常:no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
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:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
这个问题我解决了一晚上,网上教程几乎都看了一遍,还是没有解决。。。终于解决了,必须记录下来。
后面解决步骤是:
将rxtxSerial.dll
和rxtxParallel.dll
添加到java.library.path中,我使用的方法是直接add to path,就跟导入jar包的方式一样。这两个文件的官网下载地址:下载链接
我将下好的这两个dll文件和jar放入之后,又出现了新的异常
java.lang.UnsatisfiedLinkError: D:\outSourcing\SerialPort\lib\rxtxSerial.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform thrown while loading gnu.io.RXTXCommDriver
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: D:\outSourcing\SerialPort\lib\rxtxSerial.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
后面发现是版本的问题,于是我又到官网下载了下面这个版本
最后运行成功