Hi, I am confused about classpaths, packages, and directory structure. I had a program that was running, but when I made some changes to the directory structure, it stopped running. Here's what i have:
1.a directory (myclasses) with several graphing utilities I wrote a while back. Inside this directory there are the paths source\com\rephunk (where the java files are) and classes\com\rephunk. Each java file starts with �package com.rephunk�. 2.a project directory (punnett) with the same paths. In source\com\rephunk, there are two java files, one of which has the main procedure, called PunnettGui.java. These files also start with the same package statement. 3.I compile from the source folder of the project directory, using javac �cp .;c:\java\myclasses\classes;c:\java\punnett\classes �d ..\classes *.java This seems to work OK. 4.I try to run from the classes folder of the project directory, using java �cp .;c:\java\myclasses\classes com.rephunk.PunnettGui, and I get the NoClassDefFound error on the class PunnettGui. (I�ve also tried with java �cp .;c:\java\myclasses\classes;c:\java\punnett\classes com.rephunk.PunnettGui).
I would really appreciate any help!! Thank you, -Karen.
NoClassDefFound is actually different from ClassNotFound -- and is one of the most unhelpful and confusing errors out there.
Usually when you receive a NoClassDefFound, it can find the class that it's looking for. However, it cannot find a dependant class. But it won't tell you which dependant class it can't find. It jsut tells you that there's a problem with the main class.
Make sure that the classpath contains all dependant classes, and try again.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
You could try adding -verbose switch on the java command line. It will show which classes the JVM is loading. Might help isolate the problem class. It creates a long load list so you may want to redirect the output to a file and use an editor to search for your directory path/files. ex: java -verbose ... > output.txt
posted 14 years ago
Thank you for the help! Problem solved.
For the record, I looked in the classes directory and found that some of my classfiles were ending up in the wrong directory, because I had neglected to put a package statement in one file.
In addition I had left a slash out of the classpath name in the java statement. Either one was enough to scuttle the program!
Thank you again!!! -Karen. [ November 04, 2005: Message edited by: Karen Nelson ]