RAJensen
RAJensen

Reputation: 65

Raspberry pi - java - Serial Com

I've got a serious problem with my Raspberry Pi (OS: Raspbian) and Java (JDK-7-Armhf). My code wont execute without creating a Exception. I'll been reading and trying several proposals and nothing have worked yet. So now i am confused of what went wrong..? So it goes like this: I've got a Java source code that will run in my Eclipes IDE. But when i export the .jar-file, even with library (JRE System lib. _86, JavaSE1.7, JAVAX.comm), as "Runnabel JAR" or just .JAR and execute it om my Raspberry pi, i've got "NoCLassDefFoundExecption: SerialPortEventListener..! I just don't know why, it won't find the library and use it..! On my Pi i have librxtx-java installed and JDK-7-oracle-armhf. librxtx-java should be setting its JAVA_PATH on it's own when installed, but not sure that is done correct! (I've got a folder /usr/jni and it contains: librxtxSerial.so and /usr/lib/jvm/jdk-7-oracle-armhf/).

Looking at the library Javax.RXTXcomm in Eclipse, i've got RXTXcomm.jar, that contains SerialPortEventListener, so it is defininated i the .jar. I'm thinking about, could it be, that there is a missing link between my Java JVM and linux serialport driver? My JRE is working in some way, because it will execute a code to readout HOSTNAME & IP-Adress. So is there some one who knows how to fix this..?

This is a readout of Java Exception:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/comm/SerialPortEventListener
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Caused by: java.lang.ClassNotFoundException:     javax.comm.SerialPortEventListener
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 13 more

A copy of my code. "SimpleRead.java" The original from java comm API samples

Upvotes: 2

Views: 602

Answers (2)

Luca Vix
Luca Vix

Reputation: 744

You have to change the reference from javax.comm to gnu.io in your source code.

Upvotes: 1

user4580220
user4580220

Reputation:

Try following:

  1. Switch to root and run the program you created
  2. If that helps do following sudo adduser username dialout then log out and log in from all terminals and GUIs

Upvotes: 0

Related Questions