kender_a
asked on
NoClassDefFoundError
Colleagues,
I have written a program, which uses a Comm package to talk to the serial port (I'm using Sun One). It's main class is the SerialPortEventListener:
public class CTesaComm extends javax.swing.JFrame implements SerialPortEventListener {
...
}
The program build successfully, but when i try to run it, like this:
java -cp . CTesaComm
It gives this error
Exception in thread "main" java.lang.NoClassDefFoundE rror: javax/comm/SerialPort
EventListener
at java.lang.ClassLoader.defi neClass0(N ative Method)
at java.lang.ClassLoader.defi neClass(Un known Source)
at java.security.SecureClassL oader.defi neClass(Un known Source)
at java.net.URLClassLoader.de fineClass( Unknown Source)
at java.net.URLClassLoader.ac cess$100(U nknown Source)
at java.net.URLClassLoader$1. run(Unknow n Source)
at java.security.AccessContro ller.doPri vileged(Na tive Method)
at java.net.URLClassLoader.fi ndClass(Un known Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at sun.misc.Launcher$AppClass Loader.loa dClass(Unk nown Source)
at java.lang.ClassLoader.load Class(Unkn own Source)
at java.lang.ClassLoader.load ClassInter nal(Unknow n Source)
When I try to run my program without the -cp option, it gives this error:
Exception in thread "main" java.lang.NoClassDefFoundE rror: CTesaComm
Here's my CLASSPATH (system variable under XP):
C:\j2sdk1.4.2_04\lib\comm. jar; E:\n\kalaco\comm\app
The first one is the comm library, the latter one is the path to my program.
What am I doing wrong?
Thanks,
Nick
I have written a program, which uses a Comm package to talk to the serial port (I'm using Sun One). It's main class is the SerialPortEventListener:
public class CTesaComm extends javax.swing.JFrame implements SerialPortEventListener {
...
}
The program build successfully, but when i try to run it, like this:
java -cp . CTesaComm
It gives this error
Exception in thread "main" java.lang.NoClassDefFoundE
EventListener
at java.lang.ClassLoader.defi
at java.lang.ClassLoader.defi
at java.security.SecureClassL
at java.net.URLClassLoader.de
at java.net.URLClassLoader.ac
at java.net.URLClassLoader$1.
at java.security.AccessContro
at java.net.URLClassLoader.fi
at java.lang.ClassLoader.load
at sun.misc.Launcher$AppClass
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
When I try to run my program without the -cp option, it gives this error:
Exception in thread "main" java.lang.NoClassDefFoundE
Here's my CLASSPATH (system variable under XP):
C:\j2sdk1.4.2_04\lib\comm.
The first one is the comm library, the latter one is the path to my program.
What am I doing wrong?
Thanks,
Nick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>> java -cp .;%CLASSPATH% CTesaComm
It worked, and I have two additional questions:
1. My program can not find ports any more (but doesn't raise any exceptions)?
2. What should I ship to a person, who doesn't have JDK?
Thanks,
Nick
It worked, and I have two additional questions:
1. My program can not find ports any more (but doesn't raise any exceptions)?
2. What should I ship to a person, who doesn't have JDK?
Thanks,
Nick
1. I think the phrase 'any more' is a little dubious ;-) It can't have been finding them before. All i can suggest is to look closely at the examples that come with Java Comm and make sure your code mimics it.
2. What should I ship to a person, who doesn't have JDK?
They will have to install the JRE (runtime environment they don't need the SDK). Point them to the link to that on the Sun site. Alternatively you could use Java Web Start (see Sun site)
2. What should I ship to a person, who doesn't have JDK?
They will have to install the JRE (runtime environment they don't need the SDK). Point them to the link to that on the Sun site. Alternatively you could use Java Web Start (see Sun site)
ASKER
When the my application was running in the debugger it WAS successfully enumerating ports. After I wrote this question, I had copied the java.comm.properties and win32com.dll into my release and JRE folders, but it didn't help.
Oh OK - you were running in a different way before then?
Copy the dll into one of the directories revealed by running this program with the parameter "java.library.path"
/**
* Description of the Class
*
* @author CEHJ
* @created 30 March 2004
*/
public class Props {
/**
* The main program for the Props class
*
* @param args The command line arguments
*/
public static void main(String[] args) {
if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
System.out.println(System. getPropert y(args[0]) );
}
}
else {
System.getProperties().lis t(System.o ut);
}
}
}
Not sure where the props file should go - check docs
Copy the dll into one of the directories revealed by running this program with the parameter "java.library.path"
/**
* Description of the Class
*
* @author CEHJ
* @created 30 March 2004
*/
public class Props {
/**
* The main program for the Props class
*
* @param args The command line arguments
*/
public static void main(String[] args) {
if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
System.out.println(System.
}
}
else {
System.getProperties().lis
}
}
}
Not sure where the props file should go - check docs
>>Not sure where the props file should go - check docs
But almost certainly in your classpath ;-)
But almost certainly in your classpath ;-)
ASKER
I have figured out where to put the propertirs and the dll:
win32comm.dll.... C:\Program Files\JavaSoft\JRE\1.3.1_0 1\bin
comm.jar ....C:\Program Files\JavaSoft\JRE\1.3.1_0 1\lib\ext
javax.comm.properties....C :\Program Files\JavaSoft\JRE\1.3.1_0 1\lib.
win32comm.dll.... C:\Program Files\JavaSoft\JRE\1.3.1_0
comm.jar ....C:\Program Files\JavaSoft\JRE\1.3.1_0
javax.comm.properties....C
ASKER
I have another question, though, if you will.
How to make a windows shortcut to launch my app quickly?
Thasnk,
Nick
How to make a windows shortcut to launch my app quickly?
Thasnk,
Nick
Various ways
a. Right click the folder or desktop and choose 'Create shortcut'. Put same command as you do at the command line in there
b. Create an executable jar
http://www.cs.princeton.edu/introcs/80systems/jar/jar.html
a. Right click the folder or desktop and choose 'Create shortcut'. Put same command as you do at the command line in there
b. Create an executable jar
http://www.cs.princeton.edu/introcs/80systems/jar/jar.html
You can also make a batch-file which runs the command that you use to run your app, and either place the batch file on the desktop (be sure to change your directory to the directory containing the class-file), or make a short-cut to the batch file.
8-)
>>C:\j2sdk1.4.2_04\lib\com
to
.;C:\j2sdk1.4.2_04\lib\com