Java 串行通信在IDE外部运行失败

Java 串行通信在IDE外部运行失败,java,netbeans,serial-port,Java,Netbeans,Serial Port,我有一个使用comm.jar库的串行通信程序。 在Netbeans IDE中运行时,它绝对可以正常工作。 但当我运行它的jar时,它无法填充portList。 这背后的原因是什么?我在jar文件所在的lib文件夹中有必要的comm.jar文件 谢谢。您能告诉我们错误并显示您的代码吗? try{ rcvd_data=""; txt_data.setText(txt_data.getText()+"\nwrite()"); portList = CommPortIdentif

我有一个使用comm.jar库的串行通信程序。 在Netbeans IDE中运行时,它绝对可以正常工作。 但当我运行它的jar时,它无法填充portList。 这背后的原因是什么?我在jar文件所在的lib文件夹中有必要的comm.jar文件


谢谢。

您能告诉我们错误并显示您的代码吗?
try{
    rcvd_data="";
    txt_data.setText(txt_data.getText()+"\nwrite()");
    portList = CommPortIdentifier.getPortIdentifiers();
    txt_data.setText(txt_data.getText()+"\n"+portList.hasMoreElements());//getting false here when running it putside from IDE
    while (portList.hasMoreElements()) 
    {
        txt_data.setText(txt_data.getText()+"\nwhile()");
        portId = (CommPortIdentifier)portList.nextElement();

        if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
        {
            if(portId.getName().equals("COM2"))
            {
                try{
                    writeToSerial();
                    rcvd_data = readFromSerial();
                    txt_data.setText(txt_data.getText()+"\nData:"+rcvd_data);
                    serialPort.removeEventListener();
                }
                catch(Exception e){
                    System.out.println(""+e);
                    txt_data.setText(""+e.getMessage());
                }
            }
        }    
    }
    }
    catch(Exception e)
    {
        System.out.println(""+e.getMessage());
    }