I have created a servlet as a Dynamic Web Project in Eclipse, then converted it to a Maven project. I initially created it as a simple “Hello World” servlet and “Run on Server” worked fine.
I then added another (Maven) project in my workspace as a dependency and referenced one of the classes in that project. Now the servlet fails with a NoClassDefFoundError
exception as soon as a class from the dependency is referenced. What gives?
Browsing through some other question I found some helpful hints:
I tried Run as > maven install on the project, which failed with an error indicating my dependency could not be found. Turns out I needed to add my dependency to my local repo first—behavior is different from a standard Java application here.
Choose the dependency, then Run as > maven install to store the dependency in your local repository.
After that I was able to run the servlet on my server with no further issues.