Eclipse 3.2 is driving me nuts. For reasons I just can’t understand or debug, it keeps throwing
NoClassDefFoundError when I try to run most code in my project:
Exception in thread "main" java.lang.NoClassDefFoundError: nu/xom/Element
However, it can compile the classes it complains about not finding just fine. There appears to be a disconnect between the path the compiler sees and what the interpreter sees.
I can run simple Hello World applications in other subpackages (e.g.
nu.xom.samples) but not anything in the main package (
nu.xom) nor anything in a subpackage that references the main package.
I’ve tried completely reinstalling Eclipse and nuking all my preferences (not an easy task since Eclipse spews them all over various locations on the disk, and tries to hide them from the user) but to no avail. The problem reoccurs.
This is a new development. I used to be able to use Eclipse on this project. I’m not sure what changed to break that. A little googling shows that other people have had problems with similar symptoms, but it’s not clear whether it was the same root cause, or whether any of them were actually able to fix their problems.
At this point I’m about ready to chuck Eclipse completely and once again try NetBeans to see if it’s finally ready for prime time. And if it isn’t, I think there may be an offer a free copy of IDEA sitting somewhere in my Inbox that I haven’t bothered to take advantage of.
Oh my God! I just figured out what’s happening! Believe it or not, the problem is related to this. Eclipse failed to compile one file in
UnicodeUtil. That one file is extremely challenging and a real torture test for various tools. It includes some huge lookup tables that cause stack overflows in weak compilers and analyzers. It is legal Java code, and it fits within the bounds of maximum method size, but just barely. Eclipse used to be able to compile it, but it’s been weakening from milestone to milestone. A lot of tools can’t handle this class, and it looks likes between 3.2M4 or thereabouts and 3.2 final Eclipse joined that number. Previously it couldn’t analyze that class, but at least it could compile it. Now it can’t even compile it.
Still that shouldn’t have caused all my problems. It’s just one class that’s not related to a lot of the things I couldn’t run (e.g a HelloWorld program in the
nu.xom package with no dependencies on any of the rest of the package.) However, apparently Eclipse compiles in reverse alphabetical order. That is, first it compiles
XPathContext, and so on. Eventually it reaches
UnicodeWriter, and then
UnicodeUtil where it craps out. At this point it stops. It never compiles
Element, or any other class that precedes
UnicodeUtil in the alphabet. Consequently it can’t find these classes when it comes time to run code that depends on these classes.
There is indeed a disconnect between the path the compiler sees and what the interpreter sees. The compiler and editor appear to be looking at the
.java files and analyzing them directly so they don’t report any errors based on the compiler’s failure to generate corresponding
.class files. However, the runtime uses the compiled
.class files, some of which don’t exist, rather than the
.java source files that do exist.
I’m still not sure I can fix this. There’s a real Eclipse bug here causing my pain. In fact there are two: first that it can’t compile a legal file. Second that this failure blocks compilation of other files. If I can’t work around this, I’ll have to switch IDEs anyway, or perhaps just use BBEdit, Ant, and javac (none of which are the least bit fazed by
UnicodeUtil). But at least now I know what the problem is so I can stop tearing my hair out, and start moving forward.
P.S. I have a funny feeling that I might have found and fixed this problem sooner and saved myself a lot of grief if I were doing pair programming. Such are the disadvantages of working for yourself. Any agile shops hiring?