开发者

java javax.comm

Hi im trying to read com port, so I add library to my java directory like they wrote here but when Im witing simple code like

import java.util.Enumeration;
import javax.comm.*;

public class CompotCore {

    public static void main(String[] args) 
    {
        Enumeration list = CommPortIdentifier.getPortIdentifiers();
    }

}

I get such error:

java.lang.UnsatisfiedLinkError: no Serial in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
    at java.lang.Runtime.loadLibrary0(Runtime.java:840)
    at java.lang.System.loadLibrary(System.java:1047)
    at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at javax.comm.CommPortIdentifier.loadDriver(CommPortIdentifier.java:237)
    at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
    at CompotCore.main(CompotCore.java:11)
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.comm.SunrayInfo.isSessionActive()Z
    at com.sun.comm.SunrayInfo.isSessi开发者_Python百科onActive(Native Method)
    at com.sun.comm.Portmapping.registerCommPorts(Portmapping.java:155)
    at com.sun.comm.Portmapping.refreshPortDatabase(Portmapping.java:100)
    at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:138)
    at CompotCore.main(CompotCore.java:11)

i read that I had to add System.load("Serial"); with full path but I dont have such library and dont know where to find it.


On the site you link to it includes instructions to copy two native libraries into your JRE lib dir:

cp rxtx-bins.1/1.4/i386-pc-linux/libParallel.so /usr/java/j2sdk1.4.0/jre/lib/i386/
cp rxtx-bins.1/1.4/i386-pc-linux/libSerial.so /usr/java/j2sdk1.4.0/jre/lib/i386/

Are they there?

Be sure you are copying them into the correct JRE. What does which java tell you?

An alternative to copying to jre/lib would be to have them in some other location and then point to that dir with the System Property java.library.path, e.g. you would execute Java like this to start your program

java -Djava.library.path=<dir_with_those_libs> <your_other_args>

Update

OK I downloaded the rtxt tar and took a look. After you untar it, you have the following (one example):

ls -l rxtx-bins.1/1.4/i386-pc-linux/
total 44
-rwxr-xr-x 1 root root  9700 Dec  5  2001 libParallel-1.4.15.so
lrwxrwxrwx 1 root root    21 Jul  6 03:23 libParallel.so -> libParallel-1.4.15.so
-rwxr-xr-x 1 root root 31400 Dec  5  2001 libSerial-1.4.15.so
lrwxrwxrwx 1 root root    19 Jul  6 03:23 libSerial.so -> libSerial-1.4.15.so

If you followed the instructions from that page, you will have only copied the links, not the actual libs. So the solution will be to copy ALL the files, something like this:

cp rxtx-bins.1/1.4/i386-pc-linux/* /usr/java/j2sdk1.4.0/jre/lib/i386/

Or alternatively to execute Java something like:

java -Djava.library.path=~/rxtx-bins.1/1.4/i386-pc-linux:$LD_LIBRARY_PATH <your_other_args>


The page that you linked to offers you to download the RXTX package. In that archive file there are the native libraries that you need for different platforms.

You just have to make sure that Java can find the relevant native library for the OS that you are using. You can do that by specifying the directory that contains the native library in the java.library.path system property, which you can set on the command line like this:

java -Djava.library.path=C:\Folder\That\Contains\TheDLL CompotCore

For Linux, obviously:

java -Djava.library.path=/folder/that/contains/the_so CompotCore

(Ofcourse, substitute the actual directory in the command).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜