简体   繁体   English

Java应用程序在Eclipse中运行,但Jar无法找到串行端口

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

I have an application that runs in Eclipse. 我有一个在Eclipse中运行的应用程序。 It uses the RxTx code to access serial ports. 它使用RxTx代码访问串行端口。 The application uses the CommPortIdentifier to set a list of ports which it adds to a JComboBox. 该应用程序使用CommPortIdentifier设置端口列表,并将其添加到JComboBox。 This all works fine in Eclipse. 所有这些在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). 当我从Jar文件运行该应用程序时,它运行无误,但在使用串行端口并且JComboBox为空时(除了我的“未选中”除外)停滞了。 How do you debug a Jar? 您如何调试Jar? Was the RxTx library somehow not included? 是否以某种方式不包括RxTx库?

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. 如果在命令行控制台中使用命令java -jar <myjarfile.jar>执行JAR文件,您将看到控制台输出,如Eclipse所示。

If anything goes wrong while loading RXTX you should get there error messages indicating what is missing or defect. 如果在加载RXTX时出现任何问题,您应该会收到错误消息,指出缺少或存在的缺陷。

PROBLEM SOLVED - I thought that I was done when Eclipse worked after putting the rxtxSerial.dll in the bin directory of the JDK. 解决的问题-将rxtxSerial.dll放在JDK的bin目录中后,我认为当Eclipse工作时,我已经完成了工作。 The Jar did not work until I put the same file in the bin directory of the JRE. 在将相同文件放入JRE的bin目录之前,Jar无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM