Eclipse & Tomcat - Class loading

1k views Asked by At

I have recently migrated a Java Client project to a Java Server project, using Tomcat, I have found that project library dependencies may be broken.

Ordinarily I include the Libraries into the Java Build Path via the Eclipse menu option. I store the Libraries in the project \lib folder.

When I do this via a Tomcat server build I get errors on the library objects. I understand that you may need to load the libraries separately via;

Class.forName(classString);

However when I do this a NoClassDefFoundError exception is thrown. So I figure I'm loading the dependencies wrong. But how do I do that via Eclipse & Tomcat?

I should also mention that I am using the "Run On Server" feature of eclipse, just in case this changes anything regarding different requirements for running in Eclipse and deployment.

1

There are 1 answers

1
Olaf Kock On BEST ANSWER

Apart from the whole eclipse aspect: As you mention tomcat and a server project: You probably have a web application. Web applications, when deployed, include all the jar-files that are contained in WEB-INF/lib at runtime.

When everything works at compile time, eclipse is happy with the setup. When you get the NoClassDevFoundError at runtime (in tomcat), you most likely need to give tomcat a hint where to find the jar files. And that will be WEB-INF/lib