mkstlwtz
mkstlwtz

Reputation: 720

Java Application runs in Eclipse but Jar fails to find serial ports

I have an application that runs in Eclipse. It uses the RxTx code to access serial ports. The application uses the CommPortIdentifier to set a list of ports which it adds to a JComboBox. This all works fine in Eclipse.

 public void initArguments() {
    String[] args = new String[3];
    args[0] = "prot2prom.csv";
    args[1] = "COM4";
    args[2] = "Bank0";
    Scanner scan = null;
    Enumeration         portList;
    CommPortIdentifier  portId;
    String              portName;
    String              target;


        // Select The Serial Port
    target = args[1];
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
        portId = (CommPortIdentifier) portList.nextElement();
        portName = portId.getName();
        portStrings.addItem(portName);
        if( portName.equals(target) ){
            portStrings.setSelectedIndex( portStrings.getItemCount() - 1 );
        }
    }
}

When I run that application from the Jar file, it runs without error, but stalls when it goes to use the serial port and the JComboBox is empty (except for my None Selected). How do you debug a Jar? Was the RxTx library somehow not included?

Upvotes: 1

Views: 1191

Answers (2)

mkstlwtz
mkstlwtz

Reputation: 720

PROBLEM SOLVED - I thought that I was done when Eclipse worked after putting the rxtxSerial.dll in the bin directory of the JDK. The Jar did not work until I put the same file in the bin directory of the JRE.

Upvotes: 0

Robert
Robert

Reputation: 42744

If you execute the JAR file using the command java -jar <myjarfile.jar> inside a command line console you will see the console output as shown in Eclipse.

If anything goes wrong while loading RXTX you should get there error messages indicating what is missing or defect.

Upvotes: 1

Related Questions