Working my way through _Eclipse in Action_... chapter 7.... I've gotten several JSP's to work correctly under Tomcat. I've gotten a simple servlet to work correctly under Tomcat. But as soon as a servlet uses a class I've defined in another package, I get a NoClassDefFoundError. I assume something is wrong in the search paths, but I've checked every path-related Eclipse preference I can find, and they all refer to the basedir of the other packages. Do I need to do something special to tell Tomcat how to find packages at run time?
Addendum: I have confirmed that I can get a servlet to refer to a user-defined class that's defined in the same package, and I can refer to a user-defined class that's defined in another package in the same Eclipse project, but I can't get at a class that's defined in a package in a different project. Even the <em>same</em> package in a different project.
So where do I set the paths?
The most obvious one to me was "Project -> Properties -> Java Build Path -> Projects", where I checked the name of the other project where the class is defined.
Just to make sure, I also went to "Project -> Properties -> Java Build Path -> Libraries" and added the "bin" directory of said other project. (Removing this duplicate path entry doesn't help either.)
"Windows -> Preferences -> Build Order" specifies things in the right order, dependee before dependant.
Is there anyplace else I need to go to tell Eclipse how to find the classes in question?
Steven, In WSAD: The "build path" is used at compile time. The "java jar dependencies" is used at runtime. If it isn't set properly, you get runtime errors, but not compile errors. You can set the java jar dependencies by right clicking the project and selecting properties (for a web project.)
So it follows that Tomcat's classpath needs a jar for this other project.
OK, I've looked under Project -> Properties -> Tomcat -> Devloader Classpath, checked "Enable DevLoader", and checked all the relevant folders. No dice: the servlet still couldn't find classes defined in different projects. So I stopped Tomcat and re-started it; startup failed because it was unable to find the DevLoader class. I un-checked "Enable DevLoader" and re-started Tomcat, and the servlet was again unable to find classes defined in different projects.
Am I missing a component of Tomcat, or have I failed to set some option in Eclipse, or what?
author & internet detective