简体   繁体   English

将Java JAR文件移动到新计算机

[英]Moving a Java JAR file to a new machine

I have a Java program that connects to com ports when it's running. 我有一个Java程序,它在运行时连接到COM端口。 All I have is a .JAR file. 我只有一个.JAR文件。 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. 我知道串口设备可以在新机器上工作,因为我可以通过一个名为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. 当我执行.JAR文件时,它出现并且似乎运行得很好,但是无法连接到com端口。 Could this be a missing library that is installed in the JRE of the other machine? 这可能是安装在另一台机器的JRE中的缺失库吗? How would I figure out what is missing to make this program run? 我如何找出使这个程序运行的缺失?

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. Java通信端口(并行和串行端口)支持由Java Communications API提供 ,它依赖于本机代码来支持对这些端口的低级访问。 That API it's an extension to the JDK and not part of it. 该API是JDK的扩展,而不是它的一部分。

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. 编辑:对于遗留端口的跨平台支持,即使您只打算在一个平台上使用您的程序,我也推荐使用RXTX ,它是JavaComm的开源替代品。

Open the jar, look at META-INF/MANIFEST.MF file to see if it specifies any jar dependencies. 打开jar,查看META-INF / MANIFEST.MF文件以查看它是否指定任何jar依赖项。 If not, it is possible that the JAR is using some native libraries to connect to COM ports. 如果没有,JAR可能正在使用一些本机库连接到COM端口。

Using the Serial port with Java normally involves addition of a compiled native (.so or .dll) file to the LD_LIBRARY_PATH. 将串行端口与Java一起使用通常需要将已编译的本机(.so或.dll)文件添加到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) 我认为你正在使用Linux,所以在原始机器上寻找一个名为librxtxSerial.so的文件(它在Windows上被称为rxtxSerial.dll)

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: 库路径可以通过几种方式设置,但最好的办法是在原始Java安装中检查此文件:

eg /jre/lib/i386/librxtxSerial.so 例如/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). 需要注意的另一件事是rxtx jar本身(这可能已经捆绑在你的jar中,或者可能没有)。

You may get better results by simply following instructions on the RXTX website, but I'd try understanding the original installation first. 只需按照RXTX网站上的说明即可获得更好的结果,但我会首先尝试了解原始安装。

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

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM