在 Java 小程序中动态加载本机库

发布于 2024-07-15 04:59:58 字数 573 浏览 7 评论 0原文

我正在尝试编写一个将从用户串行端口读取数据的 Java 小程序。 为此,我将 Java Comm APIRXTX 库。 我已经成功地通过本地 Java 应用程序读取数据,但我似乎无法在小程序中执行相同的操作。 问题是 RXTX 库是一个本机库,我还没有找到在 Java 小程序中加载该库的方法。 我发现了两篇有趣的文章(在小程序中使用 JNI ,其中引用了 这篇文章),但两者都超过 10 岁了,我我想知道是否有更新的解决方案。 或者如果您可以提出替代方案,我很想听听!

I am trying to write a Java applet that will read from a user's serial port. For this I am using the Java Comm API in conjuction with the RXTX library. I've successfully managed to read data through a local Java application but I can't seem to do the same from within an applet. The problem is that the RXTX library is a native library and I haven't found a way to load this library inside the Java applet. I've found two interesting articles (Using JNI in Applets which references to this article), but both are over 10 years old and I am wondering if there is a newer solution. Or if you can suggest an alternative, I would love to hear it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

谢绝鈎搭 2024-07-22 04:59:58

使用 Java Web Start。 您可以将本机库作为签名 jar 包含在内,一切都应该可以正常工作。

1)将本地库放入ROOT目录下的jar中
2)在所有罐子上签名
3)编写一个引用所有jar的JNLP(去搜索如何编写jnlp)

之后它应该可以工作

Use Java Web Start. You can include the native library as a signed jar and everything should work.

1) put the native librarys in a jar in the ROOT directory
2) sign ALL the jars
3) write a JNLP referencing all the jars (go do a search on how to write jnlp's)

after that it should work

爱冒险 2024-07-22 04:59:58

首先,我建议在 Applet 中这样做可能是一个坏主意。

如果您还是继续,JNLPAppletLauncher 可能会有所帮助。

Firstly I'd suggest doing that in an Applet is probably a bad idea.

If you do go ahead anyway, JNLPAppletLauncher may help.

吃→可爱长大的 2024-07-22 04:59:58

我不了解小程序,除了它们被严格锁定之外。 安全/访问计算机资源等。

如果您需要可 Web 部署的解决方案,请查看 Java Web Start? 请特别参阅此常见问题解答条目

I don't know about applets, other than they're locked down heavily wrt. security/accessing the machine's resources etc.

If you need a web-deployable solution, have you looked at Java Web Start ? See in particular this FAQ entry

单身情人 2024-07-22 04:59:58

坦率地说,尝试从 Java 小程序访问设备是一个坏主意,即使您可以使其工作,并且将动态库加载到传统小程序中更是一个更糟糕的主意; 事实上,如果您能找到一种方法来欺骗现代浏览器来执行此操作,我会感到惊讶。 (考虑可能的安全隐患。)

按照其他问题的建议,您最好构建一个可以通过 Web Start 启动的应用程序。

Frankly, trying to access devices from a Java applet is a bad idea even if you could make it work, and loading a dynamic library into the conventional applet is an even worse idea; in fact, I'd be astounded if you could find a way to trick a modern browser into doing it. (Consider the possible security implications.)

You're better off, as suggested on other questions, building an app that can be launched with Web Start.

夏夜暖风 2024-07-22 04:59:58

我也对这里的答案很感兴趣。 我的建议是将 RXTX 的 .jar 和 .dll 安装到 \program files\java\ 树中。 您可以在尝试使用小程序之前将它们安装在目标系统上。 我喜欢使用 Java Web Start 的想法。 如果你签署了小程序,你就不能读/写机器上的任何文件了吗? 那么您可以安装 .jar 和 .dll 然后再使用它们吗?

对于 Windows,我建议使用“Windows Java Serial Com Port Driver”而不是 rxtx。
您可以从 http://www.engidea.com/blog/informatica 下载它/winjcom/winjcom.html
我发现它更容易安装和使用,而且更无错误。
我无法将 RXTX 与 USB 串行设备一起使用,因为拔出 USB 端口时 RXTX 会崩溃。 winjcom 为我解决了这些问题,甚至更多。

我仍在尝试决定如何部署 DLL,但我并不担心,因为我不希望“Windows Java Serial Com Port Driver”的 DLL 发生变化。
-斯托什

I'd be real interested in the answer here also. My suggestion would be to install the .jar and .dll for RXTX into the \program files\java\ tree. You could install them on the target system before trying to use the applet. I like the idea of using Java Web Start. If you sign the applet, can't you read/write any file on the machine? So you could install the .jar and .dll and then use them afterward?

For windows, I suggest using "Windows Java Serial Com Port Driver" rather than rxtx.
You can download it from http://www.engidea.com/blog/informatica/winjcom/winjcom.html
I've found it much easier to install and use and much more bug-free.
I was unable to use RXTX with USB serial devices because RXTX would crash when the USB port was unplugged. winjcom solved these problems for me, and more.

I'm still trying to decide how to deploy the DLL, but I'm not sweating it because I don't expect the DLL for "Windows Java Serial Com Port Driver" to change.
-Stosh

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文