Go Down

Topic: getPortIdentifiers() no working in jar file? (Read 1 time) previous topic - next topic


Hi all,

I've imported all the RXTX jar files and linked them to eclipse which works fine. However when I then export the class to a runnable jar file it fails on the following line and won't even return a exception message:

Enumeration<> portEnum = CommPortIdentifier.getPortIdentifiers();

Any ideas how to fix this?

Many Thanks,



If it works in Eclipse testing the .class file, but does not work from a jar file, you probably have a standard class/library not found issue.
( not directly related to RxTx or Processing or Arduino )

What makes it perhaps harder than usual here, is the required native library, which has to be found and must be for the desired environment ( 32 / 64 bit )

won't even return a exception message:

Native libraries can crash the JVM ! That produces an error message (and file) on a different level  :smiley-eek:
Before testing the your jar file:
Do you get the class file to execute outside Eclipse ? This shows if you have control over the required environment.
.class to .jar adds another level of possible problems.

A bit more information about your environment, what happens, and what you expect, might help us give you more hints  8)

getPortIdentifiers()  does not need many lines of code to be in a suitable environment, can you post them here ?



Basically I am trying to setup the serial port ready for input/output. Here's my code

CommPortIdentifier portId = null;
      Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
         CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
            portId = currPortId; break;
      } catch (Exception e){
         JOptionPane.showMessageDialog(null, e.getMessage());

All the libraries are within the project and native libraries are linked. It will compile in command prompt but returns the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: SerialCommunications
(wrong name: GreenhousePackage/SerialCommunications)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: SerialCommunications.  Program will exit.


Exception in thread "main" java.lang.NoClassDefFoundError: SerialCommunications
(wrong name: GreenhousePackage/SerialCommunications)
Could not find the main class: SerialCommunications.

So where's the problem understanding this message?
Something wrong with the class path or package name, CapiTaliZation ? 


It should be fine all the names are correct and all my java files are in the same package  :~


Could not find the main class

GreenhousePackage/SerialCommunications.java  has a public static main() method ?

(Well how/what did you run/debug in Eclipse ?)
Sorry, perhaps you look at this issue again after a little break ?


Well the main method is in a class called Execute - but this has the same problem. I have no idea how it runs then?

The jar file does run because I can see the GUI the problem is definitaly with the Serial Communications class

Go Up