What this code snippet is supposed to do: Detect all serial ports and print the names of the ports to the screen.
The Problem: When run in eclipse, the program detects serial ports fine; however, after exporting a runnable jar and running the jar, the jar detects NO ports. I highly doubt this has anything to do with the actual code itself (since it runs just fine in eclipse) but I've put the snippet in just in case I missed something.
What I've tried/already done/looked at:
I've considered that it might just be my computer, so I already tried running the jar on a different computer, but received the same results. I also made sure that everything is in the right place (the jar file, .dll file, and properties file). I quadruple checked to make sure that my build path included the right files.
I've already explored: http://www.oracle.com/technetwork/java/index-139971.html
I've spent the last hour searching for sites and SO questions about a problem similar to mine, but I've found no solutions.
This is the site which I based my code off of: http://en.wikibooks.org/wiki/Serial_Programming/Serial_Java#JavaComm_API
The Question: Why is this happening/How do I fix this?
Additional information: I'm using javax.comm
, with a 32 bit version of jdk 1.8.0_31, running windows 8. The jar file runs just fine (there's a separate component to it that works perfectly). No errors during compilation (or warnings), and no exceptions are being thrown. I'm running the jar using java -jar program.jar
. I know my computer has a serial port because eclipse shows COM1 when i run the program. (The program is also able to detect the parallel ports, but only in eclipse)
boolean portsDetected = false;
Enumeration portIdentifiers = CommPortIdentifier.getPortIdentifiers();
while (portIdentifiers.hasMoreElements()) {
CommPortIdentifier pid = (CommPortIdentifier)portIdentifiers.nextElement();
if ((pid.getPortType() == CommPortIdentifier.PORT_SERIAL)) {
System.out.println(pid.getName());
portsDetected = true;
}
}
if (!portsDetected) {
System.out.println("No serial ports detected");
return 0;
}
If there is anything else you need to know or would like to see, ask and ye shall receive!