I am having a terrible time getting this code to work. I either get an exception at main or a jd2xx not in java.class.path
I am relatively new to java and am using NetBeans as my IDE. I would really appreciate it if someone could take a peek at the code and tell me how to get in running in NetBeans or even via command line.
When I run the test application I get this:
>
java -Djava.library.path=".." -cp "../jd2xx.jar;." TestListener
Exception in thread "main" java.lang.NoClassDefFoundError: TestListener
Caused by: java.lang.ClassNotFoundException: TestListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
CODE HERE[
]
is found at the bottom here
I have included two versions of the jd2xx source code from two project that have it working. All I should need is the jd2xx.jar and jd2xx.dll and it should work.
In my project (I just copy-pasted the TestListener.java into a NetBeans project) have the jar included in my libraries and the IDE can resolve functions inside it but when I try to run it it gives jd2xx.jar not in java.class.path. My jar manifest says:
<pre lang="vb">Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1
Created-By: 1.6.0_22-b04 (Sun Microsystems Inc.)
Main-Class: Test.Run
Class-Path: lib/jd2xx.jar
X-COMMENT: Main-Class will be added automatically by build
And under ./dist/ theirs my jar and jd2xx.jar in in ./dist/lib
Help is appreciated, I bet its just an environment variable or something that's messed up...
package test;
import java.io.IOException;
import jd2xx.JD2XX;
import jd2xx.JD2XXEvent;
import jd2xx.JD2XXEventListener;
public class TestListener implements Runnable, JD2XXEventListener {
public TestListener() {
}
public static void main(String[] args) throws Exception {
TestListener tl = new TestListener();
JD2XX jd = new JD2XX();
jd.open(0);
jd.addEventListener(tl);
jd.notifyOnEvent(JD2XX.EVENT_RXCHAR | JD2XX.EVENT_MODEM_STATUS, true);
Thread tester = new Thread(tl);
tester.start();
try { Thread.sleep(15*1000); }
catch (InterruptedException e) {
System.out.println("InterruptedException");
}
jd.notifyOnEvent(~0, false);
}
public void jd2xxEvent(JD2XXEvent ev) {
JD2XX jd = (JD2XX)ev.getSource();
int et = ev.getEventType();
try {
if ((et & JD2XX.EVENT_RXCHAR) != 0) {
int r = jd.getQueueStatus();
System.out.println("RX event: " + new String(jd.read(r)));
}
if ((et & JD2XX.EVENT_MODEM_STATUS) != 0) {
System.out.println("Modem status event");
}
}
catch (IOException e) {
System.out.println("IOException");
}
}
public void run() {
try {
while (true) {
Thread.sleep(1*1000);
System.out.println("Too much work and no play makes Duke a dull boy");
}
}
catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}