Pages: [1]   Go Down
Author Topic: getPortIdentifiers() no working in jar file?  (Read 906 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,

Ed
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3072
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 )

Quote
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  smiley-cool

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

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

CommPortIdentifier portId = null;
      
      try{
         
      Enumeration portEnum = CommPortIdentifier.getPortIdentifiers();
         
      while(portEnum.hasMoreElements()){
         
         CommPortIdentifier currPortId = (CommPortIdentifier) portEnum.nextElement();
         if(currPortId.getName().equals(portName)){
            
            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.
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3072
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 ? 
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It should be fine all the names are correct and all my java files are in the same package  smiley-confuse
Logged

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3072
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 ?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: