简体   繁体   English

JAVA连接到COM端口,问题,RXTX库

[英]JAVA Connecting to COM port, problems, RXTX library

I have to write a program in Java that will display all the COM ports I have on my computer. 我必须用Java编写一个程序,该程序将显示我计算机上的所有COM端口。 I'm using the RXTX.Comm library. 我正在使用RXTX.Comm库。

I imported it, and while writing the code, the program did not show any errors, but after the compilation in the console showed: 我导入了它,并且在编写代码时,该程序没有显示任何错误,但是在控制台中进行编译后显示:

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" 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:83)
    at javaapplication14.JavaApplication14.listPorts(JavaApplication14.java:19)
    at javaapplication14.JavaApplication14.main(JavaApplication14.java:46)  

I do not know what's wrong with this error, I have 4 COM ports on my computer that should be displayed. 我不知道此错误是什么问题,我的计算机上有4个COM端口应显示。

The java serial library needs a 'native' component in order to run. Java串行库需要一个“本机”组件才能运行。 On windows this is a .dll, on Linux this is a .so. 在Windows上,这是.dll;在Linux上,这是.so。 This native library must be in the path of the executable to be found automatically. 此本机库必须在可执行文件的路径中才能自动找到。

If you now the location and don't want to edit the PATH environment variable you could also use -Djava.library.path JVM variable to point to the directory containing the native library. 如果现在是该位置,并且不想编辑PATH环境变量,则还可以使用-Djava.library.path JVM变量来指向包含本机库的目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM