0

I am trying to run a java program which list all available ports using Eclipse IDE in Ubuntu 14.04. My program is as follows:

import gnu.io.CommPortIdentifier;

import java.util.Enumeration;


public class ListAvailablePorts {

public void list() {  
    Enumeration ports = CommPortIdentifier.getPortIdentifiers();  

    while(ports.hasMoreElements())  
        System.out.println(((CommPortIdentifier)ports.nextElement()).getName());
}
public static void main(String[] args) {
    new ListAvailablePorts().list(); 

}

}

But it shows the following warning followed by error:

Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library     /usr/lib/jvm/java-8-oracle/jre/lib/amd64/librxtxSerial.so which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-8-oracle/jre/lib/amd64/librxtxSerial.so: /usr/lib/jvm/java-8-oracle/jre/lib/amd64/librxtxSerial.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch) thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/lib/jvm/java-8-oracle/jre/lib/amd64/librxtxSerial.so: /usr/lib/jvm/java-8-oracle/jre/lib/amd64/librxtxSerial.so: wrong ELF class: ELFCLASS32 (Possible cause: architecture word width mismatch)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1843)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
at ListAvailablePorts.list(ListAvailablePorts.java:11)
at ListAvailablePorts.main(ListAvailablePorts.java:17)
Dhaval Simaria
  • 795
  • 2
  • 12
  • 29

1 Answers1

0

Hi I had this problem as well

I use Ubuntu 12.4 on an old machine what i found was that library used was incorrect You can download the correct libraries for this from You need o also change your Java to oracle Java and follow the instructions for setting this up on Ubuntu make sure you do this first

After which update-alternatives java and select Oracle java for jvm

Instructions below on link here I would recommend you do this by hand it teaches you how to install this manually which to be fair is by far the better method

https://stackoverflow.com/questions/25729592/how-to-install-jdk-8-in-ubuntu-12-04-using-tar-gz-file

Preferably follow these instructions

How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE?

You also need to make yourself a member of uucp and dial-out otherwise you wont be able to open the serial port

See instructions for doing this below

How to add existing user to an existing group?

After this you need RXTX from the net this can be downloaded from http://rxtx.qbang.org/wiki/index.php/Download

You want rxtx 2.1-7r2 (stable) release for linux

open the zip file and follow the instructions

When it comes to installing the library use the file inside the "i686-unknown-linux-gnu" Folder and copy into your jdk / jvm folder as instructed whilst logged in as root (sudo -i) for root access

Next you will possibly want an ide

My suggestion is Netbeans again just follow instructions for installation on linux

After you have done ALL OF THE ABOVE "QUITE A PROCESS SO TAKE YOUR TIME "

Past code into Netbeans having created a project This worked for me !!

See Sample Java Code at this link here to gain better understanding

http://playground.arduino.cc/Interfacing/Java

I use this to communicate with my Arduino dev board which I prefer to write my own interfaces for

You will also need to add the relevant jar file to your project see picture below

To do this you will need to right click the library and tell the ide where to find the rxtxcomm jar file so that you can add this to your project

I had enormous success with this PS Ive only been using Ubuntu now for 4 weeks and already I'm sold on this os its that good

Mark
  • 11