Java – Error in COMM API Installation: nblibraries.properties file doesn’t exist

javanetbeansproperties-fileserial-port

I'm trying to run this sample code which is querying available com ports from here: 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);
    }
  }
}

I added comm api properly into my project, i can see my comm.jar file under Libraries folder of my project. But when i build the project, netbeans gives me this message:

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)

And when i try to run project, Netbeans gives this message:

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

Should i store my comm.jar file somewhere specifically? It's in my desktop now. Or does the problem occurs because of something else?

Best Answer

Another question of mine which wasn't answered by this community :/

And again i have write answer by my own. so here it is:

but the thing is what i write here is generally the same solution for similar questions on this site or other sites and yet i didn't work out at first 8-9 times.

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
Related Topic