我正在尝试运行此示例代码,该代码从此处查询可用的 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:
- Click on Start
- Click on Search
- Click on For Files or Folders …
- In the Left hand Side, Click on All Files and Folders
- Type in jdk* in the textbox under All or part of the file name:
- Click Search
- Look for yellow icon that looks like a folder
- 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/