将 Java JAR 文件移动到新机器

发布于 2024-09-02 04:16:55 字数 200 浏览 3 评论 0原文

我有一个 Java 程序,在运行时会连接到 com 端口。我只有一个 .JAR 文件。我最近尝试将其从运行该程序的机器移至另一台机器。我知道串行设备可以在新机器上工作,因为我可以通过一个名为 Putty 的程序与它们交互。当我执行 .JAR 文件时,它出现并且似乎运行得很好,但无法连接到 com 端口。这可能是另一台机器的 JRE 中安装的缺少库吗?我如何找出使该程序运行缺少的内容?

I have a Java program that connects to com ports when it's running. All I have is a .JAR file. I recently attempted to move this from a machine that the program runs on to another machine. I know the serial devices work on the new machine because I can interact with them thru a program called Putty. When I execute the .JAR file it comes up and seems to run just fine, but is unable to connect to the com port. Could this be a missing library that is installed in the JRE of the other machine? How would I figure out what is missing to make this program run?

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

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

发布评论

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

评论(3

终难遇 2024-09-09 04:16:55

是的,这很可能是问题所在。 Java 中的传统端口(并行和串行端口)支持由 Java Communications API 提供,它依赖于本机代码来支持对这些端口的低级别访问。该 API 是 JDK 的扩展,而不是 JDK 的一部分。

当然,也可能是在新机器上运行您的程序的用户没有访问该端口的权限,这是另一个问题。

编辑:对于旧端口的跨平台支持,即使您只想在一个平台上使用您的程序,我也建议 RXTX,JavaComm 的开源替代品。

Yes that could very well be the problem. Legacy ports (parallel and serial port) support in Java is provided by the Java Communications API, which relies on native code to support low level access to those ports. That API it's an extension to the JDK and not part of it.

Of course it could also be that on the new machine the user running your program doesn't have permissions to access the port, which is a different problem.

EDIT: For cross platform support for legacy ports, hell even if you only intend to use your program in one platform I recommend RXTX, an open source replacement for JavaComm.

薄荷港 2024-09-09 04:16:55

打开 jar,查看 META-INF/MANIFEST.MF 文件以查看它是否指定了任何 jar 依赖项。
如果没有,则 JAR 可能正在使用某些本机库来连接到 COM 端口。

Open the jar, look at META-INF/MANIFEST.MF file to see if it specifies any jar dependencies.
If not, it is possible that the JAR is using some native libraries to connect to COM ports.

一片旧的回忆 2024-09-09 04:16:55

将串行端口与 Java 一起使用通常需要将已编译的本机(.so 或 .dll)文件添加到 LD_LIBRARY_PATH。

我认为您使用的是 Linux,因此请在原始计算机上查找名为 librxtxSerial.so 的文件(在 Windows 上称为 rxtxSerial.dll)

可以通过多种方式设置库路径,但最好的选择是在原始 Java 安装中检查此文件:

例如 /jre/lib/i386/librxtxSerial.so

另一件需要注意的事情是 rxtx jar 本身(这可能已捆绑在您的 jar 中,也可能没有)。

只需按照 RXTX 网站上的说明进行操作,您可能会获得更好的结果,但我会先尝试了解原始安装。

http://rxtx.qbang.org/wiki/index.php/Installation

祝你好运!

Using the Serial port with Java normally involves addition of a compiled native (.so or .dll) file to the LD_LIBRARY_PATH.

I think you're using Linux, so look out for a file called librxtxSerial.so on the original machine (it'd be called rxtxSerial.dll on Windows)

The library path can be set in a few ways, but your best bet is to check for this file within the original Java installation:

e.g. /jre/lib/i386/librxtxSerial.so

Another thing to look out for is the rxtx jar itself (this may have been bundled inside your jar, or maybe not).

You may get better results by simply following instructions on the RXTX website, but I'd try understanding the original installation first.

http://rxtx.qbang.org/wiki/index.php/Installation

Good luck!

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