Java程序与串行通信组件RXTX [英] Java applet with rxtx components for serial communication

查看:346
本文介绍了Java程序与串行通信组件RXTX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个小程序,可以打开一个串行端口和相同的通信。我已经使用rxtxcomm.jar串行通信。我已经建立了一个小程序,在eclipese环境完美的作品。我建的Jar文件,并签署了一致,但在浏览器中运行时,控制台显示FOLL:

I am trying to build an applet that can open a serial port and communicate with the same. I have used rxtxcomm.jar for the serial communications. I have an applet built that works in the eclipese environment perfectly. I built the Jar file and signed the same, but when run in the browser the console shows the foll:

java.lang.ExceptionInInitializerError thrown while loading gnu.io.RXTXCommDriver
Exception in thread "thread applet-zhas_xbeeComm.xtalk-1" java.lang.ExceptionInInitializerError
    at zhas_xbeeComm.Xconnect$1.run(Xconnect.java:46)
    at java.security.AccessController.doPrivileged(Native Method)
    at zhas_xbeeComm.Xconnect.connect(Xconnect.java:40)
    at zhas_xbeeComm.xtalk.init(xtalk.java:22)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission loadLibrary.rxtxSerial)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkLink(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:123)
    ... 6 more

我甚至使用doPrivileged方法在各地的连接和开放的功能,但它是不是工作!请帮忙!!
这里是小程序的code的一个片段:
    {
    / **功能打开一个端口,并开始阅读和写作* /

I have even used doPrivileged method around the connect and open functions but it aint working! Please help!! Here is a snippet of the code of the applet: { /** Function to open a port and begin reading and writing */

public void connect ( final String portName ) throws Exception
{   

    AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
        // privileged code goes here, for example:

        // 1. added try catch for no such port exception;
        try {
            portIdentifier = CommPortIdentifier.getPortIdentifier(portName); //line 46
            } catch (NoSuchPortException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            }

}

推荐答案

刚刚有同样的问题。
请确保以RXTX库中的第一个电话是doPrivileged的块。
如果它会尝试特权块前装载库 - 它会失败,此错误

Just had the same problem. Please make sure that the first call to RXTX library is in doPrivileged block. If it will try to load library before privileged block - it will fail with this error.

一些额外的信息:
http://hacky.typepad.com/blog/2009 /05/using-rxtxcomm-in-applets.html

这篇关于Java程序与串行通信组件RXTX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆