?
Solved

NoClassDefFoundError

Posted on 2004-04-01
12
Medium Priority
?
866 Views
Last Modified: 2013-11-23
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.NoClassDefFoundError: javax/comm/SerialPort
EventListener
        at java.lang.ClassLoader.defineClass0(Native Method)
        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$100(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)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)

When I try to run my program without the -cp option, it gives this error:

Exception in thread "main" java.lang.NoClassDefFoundError: 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
0
Comment
Question by:kender_a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
12 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10735587
Change

>>java -cp . CTesaComm


to


java -cp .;%CLASSPATH% CTesaComm
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10735605
If you have a classpath set, you should probably add the current directory to it so change:

>>C:\j2sdk1.4.2_04\lib\comm.jar; E:\n\kalaco\comm\app


to

.;C:\j2sdk1.4.2_04\lib\comm.jar;E:\n\kalaco\comm\app



0
 
LVL 1

Author Comment

by:kender_a
ID: 10735690
>> 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
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 86

Expert Comment

by:CEHJ
ID: 10735737
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)
0
 
LVL 1

Author Comment

by:kender_a
ID: 10735845
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10735917
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.getProperty(args[0]));
                        }
                }
                else {
                        System.getProperties().list(System.out);
                }
        }
}

Not sure where the props file should go - check docs
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10735974
>>Not sure where the props file should go - check docs

But almost certainly in your classpath ;-)
0
 
LVL 1

Author Comment

by:kender_a
ID: 10743487
I have figured out where to put the propertirs and the dll:

win32comm.dll.... C:\Program Files\JavaSoft\JRE\1.3.1_01\bin

comm.jar ....C:\Program Files\JavaSoft\JRE\1.3.1_01\lib\ext

javax.comm.properties....C:\Program Files\JavaSoft\JRE\1.3.1_01\lib.
0
 
LVL 1

Author Comment

by:kender_a
ID: 10743496
I have another question, though, if you will.

How to make a windows shortcut to launch my app quickly?

Thasnk,
Nick
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10743533
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
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10751690
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.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10769828
8-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question