Search code examples
javaeclipserxtx

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?


Solution

  • 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.