Java applet with rxtx components for serial communication(用于串行通信的带有 rxtx 组件的 Java 小程序)
问题描述
我正在尝试构建一个可以打开串行端口并与之通信的小程序.我使用 rxtxcomm.jar 进行串行通信.我构建了一个可以在 eclipese 环境中完美运行的小程序.我构建了 Jar 文件并对其进行了签名,但是在浏览器中运行时,控制台会显示以下内容:
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
我什至在 connect 和 open 函数周围使用了 doPrivileged 方法,但它不起作用!请帮忙!!这是小程序的代码片段:{/** 打开一个端口并开始读写的函数 */
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
这篇关于用于串行通信的带有 rxtx 组件的 Java 小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于串行通信的带有 rxtx 组件的 Java 小程序
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
