java - COMM API安装错误: nblibraries.属性文件不存在

标签 java netbeans serial-port properties-file

我正在尝试运行此示例代码,该代码从此处查询可用的 com 端口:http://www.java2s.com/Code/Java/Development-Class/QueryingAvailableCOMPorts.htm

// Install the Java Comm API first. if there is no necessary file, say Dll files, the API 
// won't work.

import java.util.Enumeration;

import javax.comm.*;
import java.util.Enumeration;

public class ListPorts {
  public static void main(String args[]) {
    Enumeration ports = CommPortIdentifier.getPortIdentifiers();
    while (ports.hasMoreElements()) {
      CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
      String type;
      switch (port.getPortType()) {
      case CommPortIdentifier.PORT_PARALLEL:
        type = "Parallel";
        break;
      case CommPortIdentifier.PORT_SERIAL:
        type = "Serial";
        break;
      default: /// Shouldn't happen
        type = "Unknown";
        break;
      }
      System.out.println(port.getName() + ": " + type);
    }
  }
}

我将 comm api 正确添加到我的项目中,我可以在项目的 Libraries 文件夹下看到我的 comm.jar 文件。但是当我构建项目时,netbeans 给了我这样的消息:

ant -f C:\Users\Timur\Documents\NetBeansProjects\KEYCON clean jar C:\Users\Timur\Documents\NetBeansProjects\KEYCON\nbproject\build-impl.xml:63: Source resource does not exist: C:\Users\Timur\Desktop\javax.comm\nblibraries.properties BUILD FAILED (total time: 0 seconds)

当我尝试运行项目时,Netbeans 会给出以下消息:

run: Error loading win32com: java.lang.UnsatisfiedLinkError: no win32com in java.library.path BUILD SUCCESSFUL (total time: 0 seconds)

我应该将 comm.jar 文件存储在特定的地方吗?它现在在我的桌面上。还是由于其他原因导致出现此问题?

最佳答案

我的另一个问题,这个社区没有回答:/

我再次自己写了答案。所以这里是:

但问题是,我在这里写的内容通常是针对此网站或其他网站上的类似问题的相同解决方案,但我一开始 8-9 次都没有解决。

For the jdk (Java Developnment Kit) to recognize the serial ports on your machine, it is important to properly place these files in the right folders on your local machine :

%Java_HOME% = the location of your jdk directory.

To Find your JDK directory, Use the Following steps:

  1. Click on Start
  2. Click on Search
  3. Click on For Files or Folders …
  4. In the Left hand Side, Click on All Files and Folders
  5. Type in jdk* in the textbox under All or part of the file name:
  6. Click Search
  7. Look for yellow icon that looks like a folder
  8. Double Clikc on the folder to open the jdk folder

comm.jar should be placed in:

%JAVA_HOME%/lib

%JAVA_HOME%/jre/lib/ext win32com.dll should be placed in:

%JAVA_HOME%/bin

%JAVA_HOME%/jre/bin

%windir%System32 javax.comm.properties should be placed in:

%JAVA_HOME%/lib

%JAVA_HOME%/jre/lib

关于java - COMM API安装错误: nblibraries.属性文件不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14621204/

相关文章:

java - 在java中添加类

java - 无法执行目标 org.apache.maven.plugins :maven-compiler-plugin

java - 为 Netbeans 6.8 开发插件

c - Linux串口-wrtie()字节通过串口到目标设备

java - 如何验证特定命名的 json 架构?

java - 如何记录错误并在 orElseThrow() 子句中引发异常?

java - 我将使用什么代码将括号括在所有出现的术语/子字符串周围?

java - nxn 棋盘上 n 个玩家的 Tic tac Toe - 检查获胜者

java - 如何在 Java 应用程序中获取电话号码?

windows - 如何以编程方式将 COM51 等名称关联到 Microsoft Windows 中的物理串行端口?