Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

How to install The Java Communications API in a Windows Environment

Posted by Circuit Negma on February 7, 2007


Fix to the previous Port on :: ” How to install The Java Communications API “.
————————————————————————————-

There is a trick to install the Java Communications API correctly on a Windows system Machine. The following files are the core of JAVA Communiccation API, and they are very important to have them installed on your system for a proper operation:

  • comm.jar
  • win32com.dll
  • javax.comm.properties

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

Download Link:

coming soon

99 Responses to “How to install The Java Communications API in a Windows Environment”

  1. hamed said

    Thanks.

  2. aser hasan said

    I dont know what to say,But realy Very Very thank to you professional

  3. Billy said

    This was exactly what I needed, Thank-you.

  4. a said

    many thanx man

  5. pegah said

    wow it was great.
    thanks

  6. Five said

    *thumps up*
    thx!! =)

  7. satyam said

    i did they same but the program is throwing compile time exception
    its
    java.lang.noclassdiffounderror: javax/comm/commportidentifier

    i think my javax.comm is not installed properly plz suggest some thing.
    satyam

    • please verify the following:
      1. is java jdk is instsalled

      2. replace the following files in the following directories:
      [-win32com.dll-] should be copied to the following directories:
      %JAVA_HOME%/bin == C:\Program Files\Java\jdk1.5.0_10\bin
      %JAVA_HOME%/jre/bin == C:\Program Files\Java\jdk1.5.0_10\jre\bin
      %windir%/System32 == C:\windows\system32
      Here is how to copy the file to the above directories:
      a. click start
      b. click run
      c. type in one of the above directories in the textfield and hit ENTER, this will pop-up a window directed to the specified directory. if this does not work, this means that your windows system environmental variables for java is missing.
      d. copy the file to that directory.

      [-comm.jar-] should be copied to the following directories:
      %JAVA_HOME%/lib == C:\Program Files\Java\jdk1.5.0_10\lib
      %JAVA_HOME%/jre/lib/ext == C:\Program Files\Java\jdk1.5.0_10\jre\lib\ext

      [-javax.comm.properties-] should be copied to the following directories:
      %JAVA_HOME%/lib == C:\Program Files\Java\jdk1.5.0_10\lib
      %JAVA_HOME%/jre/lib == C:\Program Files\Java\jdk1.5.0_10\jre\lib

      3. you need to include comm.jar in your project settings or properties
      this is an example, I use netbeans for my java developments:

      Here is a sample code:

      //Sun’s serial port driver
      import javax.comm.*;
      import java.io.*;
      import java.util.*;

      public class com implements Runnable, SerialPortEventListener {

      static CommPortIdentifier portId1;
      static CommPortIdentifier portId2;

      InputStream inputStream;
      OutputStream outputStream;
      SerialPort serialPort1, serialPort2;
      Thread readThread;
      protected String divertCode = “10”;
      static String TimeStamp;

      public com()
      {
      try
      {
      TimeStamp = new java.util.Date().toString();
      serialPort1 = (SerialPort) portId1.open(“portId1(” + portId1.getName().toString() + “)”, 1000);
      System.out.println(TimeStamp + “: ” + portId1.getName() + ” opened for scanner input”);

      }
      catch (PortInUseException e)
      {}

      try
      {
      inputStream = serialPort1.getInputStream();
      }
      catch (IOException e)
      {}

      try
      {
      serialPort1.addEventListener(this);
      }
      catch (TooManyListenersException e)
      {}

      serialPort1.notifyOnDataAvailable(true);

      try
      {
      serialPort1.setSerialPortParams(38400,
      SerialPort.DATABITS_8,
      SerialPort.STOPBITS_1,
      SerialPort.PARITY_NONE);

      serialPort1.setDTR(false);
      serialPort1.setRTS(true);

      }
      catch (UnsupportedCommOperationException e)
      {}

      readThread = new Thread(this);
      readThread.start();
      }

      public void run()
      {
      try
      {
      Thread.sleep(100);
      }
      catch (InterruptedException e) {}
      }

      public static void main(String[] args) {

      try
      {
      // Scan for available ports on local host machine.
      CommPortIdentifier cpi = null;
      for (Enumeration e = CommPortIdentifier.getPortIdentifiers() ; e.hasMoreElements() 😉
      {
      CommPortIdentifier tmp = (CommPortIdentifier)e.nextElement();
      System.out.println(“COM = ” + tmp.getName().toString() + ” mem = ” + tmp.toString());
      System.out.println(“e = ” + e.toString());

      if (tmp.getName().equals(“COM1”))
      {
      cpi = tmp;
      System.out.println(“this is COM1: string”);
      break;
      }
      }

      // Defien a port manually
      portId1 = CommPortIdentifier.getPortIdentifier(“COM1”);

      // Create new COM thread and start listening to the port.
      com reader = new com();

      }

      catch
      (Exception e) {
      TimeStamp = new java.util.Date().toString();
      System.out.println(TimeStamp + portId1.getName().toString() + portId1);
      System.out.println(TimeStamp + “: msg1 – ” + e);
      }
      }

      public void serialEvent(SerialPortEvent event) {
      switch(event.getEventType()) {
      case SerialPortEvent.BI:
      case SerialPortEvent.OE:
      case SerialPortEvent.FE:
      case SerialPortEvent.PE:
      case SerialPortEvent.CD:
      case SerialPortEvent.CTS:
      case SerialPortEvent.DSR:
      case SerialPortEvent.RI:
      case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
      break;
      case SerialPortEvent.DATA_AVAILABLE:
      StringBuffer readBuffer = new StringBuffer();
      int c;
      try
      {
      c=inputStream.read();
      while ( (c != 1) || (c != 2) || (c != 3) || (c != 4))
      {
      //readBuffer.append((char) c);
      System.out.print(c);
      }

      String scannedInput = readBuffer.toString();
      TimeStamp = new java.util.Date().toString();
      System.out.println(TimeStamp + “: scanned input received:” + scannedInput);

      inputStream.close();

      readBuffer = new StringBuffer(0);
      /* if(scannedInput.substring(0,1).equals(“F”)){
      outputStream = serialPort1.getOutputStream();
      outputStream.write(divertCode.getBytes());
      System.out.println(TimeStamp + “: diverter fired”);
      outputStream.close();
      }
      else
      {
      System.out.println(TimeStamp + “: diverter not diverted”);
      }
      */
      } catch (IOException e) {}

      break;
      }
      }
      }

      • neha said

        he thanx,it helped me alot,i waz not able to solve this problem from last 1 week,thanx,now i can very well proceed with my project,thanx again

  8. Vlatko said

    Hi, I've done the previous but it is not working. import javax.comm.*; can't pass.

    I have no idea why?

    Vlatko

  9. Vlatko said


    actually, I found it. In some of the previous comments was said that you should place files in ...jdk... folder. But when you open a project, check for the path of the already added libraries(below the package folder in solution explorer).

    In my project that folder was ...jre... instead of ...jdk...

    greetings

  10. Vlatko said

    I was happy when found your explanation. I still am. :)

    Thank you.

  11. Vlatko said


    And can someone tell me how to do the same under Unix platform?

    Tnaks,
    Vlatko

  12. Vlatko said


    I've tried and worked that with rxtxComm.

    http://www.captain.at/howto-java-serial-port-javax-comm-rxtx.php

    I am trying to do it with comm.jar(your win version but for linux).
    You know, that gnu.io.* got the same functions as your javax.comm. Is it posible to find
    it for linux. Just that properties.
    In properties, there is a win32 and so...
    But, it is not so important for me to work with javax.comm, I am a biginner. :)

    I am a recent linux user. You know, it is not so bad and scary.

    Greetings,

    • Linux is not so hard to learn. as long as you understand the system ext., system folders and some basic commands, you will be surprised how easy it is.

      I used Linux long time ago for my school. but I stopped using it since I finished schools and turned back to windows because most of my design softwares run on windows only.

      As much as I would like to help every one with the Comm api, I am no longer have a linux machine for experiments.

      If you do find the solution would you be so kind to post it here so that every one could learn from your help.

      thank you so much Vlatko

  13. smn_007 said

    hai…
    I have a java program to poll a sensor device every 2 min…. The program uses java comm to read and write data to it. I have java servlet program that has to access the serial port at the same time as the polling program to read/write data from it….. I.It works individually….it is not possible to access the serial port at the same time….. Can any time slice help….. or anything which could get it done
    plz can anyone help with it….
    the project has to completed within a week

    Thanks in advance
    smn

  14. smn_007 said

    hai…

    Can 2 threads access the serial port through wait and notify…. can anyone help me with the code…. using java comm package

    smn

  15. Shaswat said

    Thnks…..

  16. Jecelyn said

    Cool man, u really help me out!! Thanks lot!

  17. Caesar said

    hi all

    I’m seeking this guide to properly install the javax.comm extension.
    I don’t know well how it works…
    I really need to map COM ports using the JAVA ICA Client through Adito Open VLS, by the time i ‘ve “drive and printer mapping” working great but unfortunately in a citrix troubleshooting guide says that COM port MAPPING is not supported by de JICA Client Applet. =(

    I really need it working cuz my App works with Epson Fiscal Printers that only can communicate through that annoying COM port

    BTW Thanks a lot to all of you. My apollogies, my english sucks…

    César

  18. smn_07 said

    Hey the how to install java comm api can be found on this page which was posted earlier in this website…

    How to install The Java Communications API in a Windows Environment

    this will definetly help u out

  19. Dan said

    Hi,

    I installed as per your instruction. But it is not working for me. What OS you are using?
    I am on Windows Vista. Is it possible to access direct IO from the user-mode? as per my knowledge, from windows XP onwards we need a SYS file to access the IO directly. Can you help me out?

    Regards,
    Dan

    • Hi Dan,

      I was using Windows XP. Then I moved to xp once I was done with my project.

      Sorry, I do not know to to get the API working on XP.

      However, I knew that to obtain a COM (port) you need to obtain an ownership of the targeted port. Under XP this is very trivial as XP will let you take over the ownership, where as the Vista OS would not let to do until you identify your self as the administrator to gain ownership of that port, thu I could be wrong.

      Also, I do not know if this API is compatible with Vista.

      try thin one : GiovynetSerialPort1.3

      Try to sear google such keywords as : java communication api for vista

      hopefully this will help you

  20. DINESH Rajapaksha said

    Thnx a Lot…!! now its wokring !
    this will help a lot in my Final year project :))

    thnx again

  21. tuansoibk said

    thanks a lot, it’s really helpful!

  22. jiggy360 said

    Im not able to run sample program in windows…
    Exception in thread “main” java.lang.NoClassDefFoundError: javax/comm/CommPortIdentifier

    I have installed everything exactly stated above.. still im getting this error
    please help!!!

  23. sundarrajan said

    hi sir

    i need a help urgent … help me for my project

    I just need to list the comm ports available in windows. i have successfully the javax.comm package as you have mentioned earlier in this blog.

    I m having this program


    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);
    }
    }
    }

    The above program is compiling well and good in my system.. but when i try to run it its shows me the error as

    Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading
    driver com.sun.comm.Win32Driver
    Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialPar
    allel in java.library.path
    Caught java.lang.UnsatisfiedLinkError: com.sun.comm.SolarisDriver.readRegistrySe
    rial(Ljava/util/Vector;Ljava/lang/String;)I while loading driver com.sun.comm.So
    larisDriver

    I have done all the things clear.. but i m ambiguous where the problem is .

    Thanks in advance

    Please try to run this program in your system and then reply for me

    • I love to help out, but there is one small problem. My new computer does not have any COM ports, However, I am going to try to compile you code. Also, I am going to look for my old code that did utilize COM ports on my old machine and post it here.

    • Ok, so I compiled you code on my machine, and as you said it does compile, but I cannot run it on my machine because it is Vista 64-bit machine.

      Netbeans IDE shoes the following error every time I try to run the code:

       run:
      Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_17\jre\bin\win32com.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
      BUILD SUCCESSFUL (total time: 0 seconds)
      

      I am going to look for the old codes and post them here.

  24. Vijay said

    Dear Circuit Negma,

    Thank you very very much. It is what exactly I was looking for and I did not find any exact solution in this clear way till I visited your post here.

    Thanks a lot,
    Vijay

  25. Ryan said

    Hi,
    I can’t thank you enough!!
    This really helped!!

    >>Ryan

  26. Commenter said

    Extra Ordinary Tutorial!

  27. Dean Shah said

    Very great writing. Honest!

  28. David said

    Thank you!

    Works like a charm!!

    Thank you very much, I had been searching for this the entire morning!!

    David

  29. BALAJI said

    Hai all,
    This is the error i am getting.
    pls help me on that issue if some one already gone through this issues.advance thaks to you

    Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading driver com.sun.comm.Win32Driver
    Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path
    Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver

  30. BALAJI said

    Hai all,

    I have already placed the required jar,properties and dll files in the correct directories.

    Caught java.lang.ClassNotFoundException: com.sun.comm.Win32Driver while loading driver com.sun.comm.Win32Driver
    Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path
    Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver

    Pls help me on that above issue.

  31. Darren said

    Oh my god!

    you saved my life! thank you thank you thank you thank you!

    I couldn’t have figured this out without you. My app now finds the javax.comm package and complies no problems 🙂

  32. prajee said

    Thank you 🙂

    You really helped me.

  33. Deji Balogun said

    While running my program, the following error came up: Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_15\jre\bin\win32com.dll: Can’t load IA 32-bit .dll on a AMD 64-bit platform. Please, what can I do to correct this as I need it for my project to work today?

    • Last time I did this on a 64bit machine, I got the same results. it seems that the driver is built for a 32bit machine only. Since this driver is no longer under development there is not much to do about it. I would suggest that you get hold of a 32bit machine and finish your project on that one.

      I tried to make this version of driver to support 64bit machine but I was not successful.

      If you search google for ‘java communication api 64?bit’, you might find someone who is already done it.

  34. charts said

    I want to install java in wondows.

  35. Shakti Panda said

    hi,we have installed the seril communication packages i.e jar,dll and properties in the maneer suggested by you in the above posts. the code is as given
    package Serial_Communication;

    import java.io.*;
    import java.util.*;
    import javax.comm.*; // for SUN’s serial/parallel port libraries

    import java.io.BufferedWriter;
    import java.io.Writer;
    import java.io.FileWriter;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;

    public class nulltest implements Runnable, SerialPortEventListener {
    static CommPortIdentifier portId;
    static CommPortIdentifier saveportId;
    static Enumeration portList;
    InputStream inputStream;
    SerialPort serialPort;
    Thread readThread;
    Writer writer = null;

    static String messageString = “Hello, world!”;
    static OutputStream outputStream;
    static boolean outputBufferEmptyFlag = false;

    public static void main(String[] args) {
    boolean portFound = false;
    String defaultPort;

    // determine the name of the serial port on several operating systems
    String osname = System.getProperty(“os.name”,””).toLowerCase();
    if ( osname.startsWith(“windows”) ) {
    // windows
    defaultPort = “COM1”;
    } else if (osname.startsWith(“linux”)) {
    // linux
    defaultPort = “/dev/ttyS0”;
    } else if ( osname.startsWith(“mac”) ) {
    // mac
    defaultPort = “????”;
    } else {
    System.out.println(“Sorry, your operating system is not supported”);
    return;
    }

    if (args.length > 0) {
    defaultPort = args[0];
    }
    System.out.println(“Set default port to “+defaultPort);

    // parse ports and if the default port is found, initialized the reader
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
    portId = (CommPortIdentifier) portList.nextElement();
    System.out.println(portId.getName());
    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {

    if (portId.getName().equals(defaultPort)) {
    System.out.println(“Found port: “+defaultPort);
    portFound = true;
    // init reader thread
    nulltest reader = new nulltest();
    }
    }

    }
    if (!portFound) {
    System.out.println(“port ” + defaultPort + ” not found.”);
    }

    }
    public nulltest() {
    // initalize serial port
    try {
    serialPort = (SerialPort) portId.open(“SimpleReadApp”, 2000);
    } catch (PortInUseException e) {}

    try {
    inputStream = serialPort.getInputStream();
    } catch (IOException e) {}

    try {
    serialPort.addEventListener(this);
    } catch (TooManyListenersException e) {}

    // activate the DATA_AVAILABLE notifier
    serialPort.notifyOnDataAvailable(true);

    try {
    // set port parameters
    serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8,
    SerialPort.STOPBITS_1,
    SerialPort.PARITY_NONE);
    } catch (UnsupportedCommOperationException e) {}

    // start the read thread
    readThread = new Thread(this);
    readThread.start();

    }

    public void run() {
    // first thing in the thread, we initialize the write operation
    // initwritetoport();
    try {
    while (true) {
    // write string to port, the serialEvent will read it
    // writetoport();
    Thread.sleep(1000);
    }
    } catch (InterruptedException e) {}
    }

    public void delay(){
    try {
    Thread.sleep(3000L);
    }
    catch (InterruptedException e) {}
    }

    public void serialEvent(SerialPortEvent event) {
    switch (event.getEventType()) {
    case SerialPortEvent.BI:
    case SerialPortEvent.OE:
    case SerialPortEvent.FE:
    case SerialPortEvent.PE:
    case SerialPortEvent.CD:
    case SerialPortEvent.CTS:
    case SerialPortEvent.DSR:
    case SerialPortEvent.RI:
    case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    break;
    case SerialPortEvent.DATA_AVAILABLE:
    // we get here if data has been received
    byte[] readBuffer = new byte[20];

    try {
    // read data
    while (inputStream.available() > 0) {
    int numBytes = inputStream.read(readBuffer);
    }

    File file = new File(“D://Serial_Comm.text”) ;//Adress where the file(here text file) to be made

    /* print data*/
    String result = new String(readBuffer);
    System.out.println(“Read: “+result);

    try{
    writer = new BufferedWriter(new FileWriter(file,true));
    writer.write(result+”\n”);
    writer.flush();

    }catch(FileNotFoundException e){
    e.printStackTrace();
    }
    catch (IOException e){
    e.printStackTrace();
    } finally{

    try
    {
    if (writer != null){
    writer.close();
    }
    } catch (IOException e){
    e.printStackTrace();
    }

    }
    }catch (IOException e) {}

    delay(); // This is used to sense data within a particular instant,here,3 seconds
    break;
    }
    }

    }

    However we are facing an error in the line
    public class nulltest implements Runnable, SerialPortEventListener

    and the error is reported as class nulltest is public, should be declared in a file named nulltest.java

    please help us out

  36. kishor said

    Go Here You’ll get Installer to Do that

    http://kishor15389.blogspot.com/2011/05/how-to-install-java-communications.html

  37. Techie said

    Could you pls send a link from where I can download win32com.dll

  38. This is really 1 great post.

  39. Darren said

    You sir are a fooking genius
    If ever meet you at a bar, I will buy you several drinks

    You saved me 🙂

  40. arun said

    I downloaded java communication API but it doesnot contain all three files that you mentioned where i can get this

    thank you

  41. khan said

    Could you guyes please help me to set up Java Comm Api for window 7 64 bit

  42. Brian said

    Hi,

    Thanks for all the information as I’ve been trying to set this up for awhile.
    I’ve followed your instructions above but i still seem to be having some trouble
    I’m getting the error:

    Error loading win32com: java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jdk1.6.0_26\jre\bin\win32com.dll: Can’t find dependent libraries

    I’ve placed win32com.dll is all the places mentioned above as well as the properties file and the jar file.
    Any help would be appreciated.

    Thanks

    Running on NetBeans 7 IDE on a Windows 7 Machine.

    • Brian said

      I found that i’m running Windows 7 64bit which cannot find the win32com.dll… need win64com.dll i think. i’ve switched to RxTx 64bit and everything is working find now.

      Thanks

  43. […] RXTXcomm Installationsanweisung | Alternative Anleitung […]

  44. Rkumar said

    Hi, it was very helpful. im trying out for a sample application to send sms from my Micromax Q2 mobile. It is throwing NoSuchPortException. can u send me a sample java code to send sms?

  45. thank you v much, .

  46. jhon said

    Hi, Thank you for your code. i kept all the files in jdk folder whatever you mentioned like that, but it is giving exception like–” Exception in thread “main” java.lang.NoSuchMethodError: main”

    pls tell me what can i do.

  47. omkar said

    I cant find the java comm api..the link you gave is nothing but a fedaral notice..

  48. vamsi said

    when i am using CommPortIdentifier.getPortIdentifier(“COM4”); i get the exception javax.comm.NoSuchPortException
    at javax.comm.CommPortIdentifier.getPortIdentifier
    i phone is also connected to the com4..
    when i am using Enumeration enu = CommPortIdentifier.getCommPortIdentifiers();
    no exception and no output
    i want solution for that

  49. vinayaka said

    can any one let me know procedure for installing comm api in netbeans
    please

    thank you.

    • 1. you need to install API on your system.
      2. you need to add the comm.jar to your project. If I remember correctly, you add the jar file under libraries in the Project workspace/explorer.

  50. Paiker said

    I will be really very thankfull for ur support.

    I have made and appplet which is reading the data from the machine attached to the serial port.
    And it is working fine when i am running it from the Eclipse..

    But when i am trying to add this applet in the HTML page it is not running and in the console this error is coming .

    java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/comm/PortInUseException
    at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: javax/comm/PortInUseException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.awt.EventQueue$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: javax.comm.PortInUseException
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    … 20 more
    Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/comm/PortInUseException

    • 1. Since the API works in a stand alone applet, then the API is installed correctly.

      2. I never worked with embedded applet for HTML. I do not think the problem is coming from the COM API, because we know it works on your machine. I would suggest that you build a simple applet that shows a “hello” message and then try to embed it in HTML. if your steps of embedding java is correct then try again with your serial port applet

      3. I wonder if windows allows a remote access of serial port through HTML!!!!!!!

      hopefully this will put you on the right direction

    • Raj said

      Before u execute an applet, make sure all the ports are stopped. Also u can add RXTXComm.jar to the classpath.. Regards, Raj..

  51. Anand said

    Thanx This is what I m needed.
    Its really help me….

  52. DS said

    i m facing this exception when i run my java app..i cant undstnd wats happng cz at one instance it runs perfectly but nxt time it dsnt..and den after it dsnt run for a long period of time..i hvnt found ne solution yet pls provide one.

    Trying to open COM4…
    Apr 7, 2012 10:54:49 PM ManagerInterface initSerial
    SEVERE: null
    javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
    at javax.comm.CommPortIdentifier.open(CommPortIdentifier.java:337)
    at ManagerInterface.initSerial(ManagerInterface.java:536)
    at ManagerInterface.initCommunication(ManagerInterface.java:518)
    at PortSelector.startButtonMouseClicked(PortSelector.java:237)
    at PortSelector.access$0(PortSelector.java:231)
    at PortSelector$1.mouseClicked(PortSelector.java:63)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    • 1. first line of errors says that COM4 is being used by Unknow windows Application. before you run your java appley, you need to close any software that uses COM4
      2. if you look through the comments on this post you will notice couple of codes samples. you should be able to tailor them to your needs.

  53. prajwal said

    thumbs up!! thanks a lot..

  54. Andres said

    where can I find this files? I mean, download the comm.jar, win32com.dll and javax.comm.properties files.

  55. Mustafa said

    Thaaaaaaaaaank u v.much

  56. stephenmwongela said

    Reblogged this on Computer World.

  57. abraham ks said

    hi in my project i did’nt get seriel communication properly so pls give a code for that.

    • the API mentioned in this article does not work on Windows 7 64-bit and any 64-bit machines. you need to search google for what is new on talking with serial ports in Java

      also, in the commments, I have posted a code for serial communication.

  58. sagar said

    Very very helpfull thanks alot

    best explanation i saw

    thank you
    god bless you 🙂

  59. migz said

    It took me two days to figure out why my code wasn’t working, it as because I didn’t have the comm library properly installed, and your way was the only way that worked!

  60. sathish kumar khammam said

    thank you very much……

  61. matpyam said

    hye..can i ask something..
    i already downloaded all the thing that need here http://smslib.org/download/
    but, me can’t fing the file comm.jar, javax.comm.properties and win32com.dll..
    realy2 need help..:(

  62. Software said

    Wow that was odd. I just wrote an extremely long comment but after I clicked
    submit my comment didn’t show up. Grrrr… well I’m not writing all that over again.
    Regardless, just wanted to say superb blog!

  63. chintan said

    Thank you , it’s really helpful

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.