Moving a Java JAR file to a new machine
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 th开发者_Python百科em 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?
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.
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.
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!
精彩评论