I was using Eclipse to create a relatively simple Dynamic Web Project that used Ivy for dependency mangement. Also, I wanted to use Eclipse’s export to a WAR feature so I would not need to write a build script. My WAR file was created, but after deploying my web app to Tomcat and starting I received this error:
SEVERE: Servlet /EntitySandboxWeb threw load() exception java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529) at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1143) at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087) at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5210) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5493) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
I found this error confusing as I knew Ivy had pulled down the dependent libraries my project needed. I decided to look at the generated WAR file and discovered those libraries were not in the WEB-INF/lib directory.
The solution was simple.
- Under Project Properties, select “Deployment Assembly”.
- Click the “Add…” button
- On the first screen of the wizard, choose “Java Build Path Entries” and click “Next”.
- On the second screen of the wizard, select “Ivy” and click “Finish”.
- You can change the “Deploy Path” if necessary (the default is “WEB-INF/lib”).
- Export your project to a WAR file again and the Ivy libraries should be in the WEB-INF/lib directory now.