17

I have a simple web app using that uses servlets. I created it as a maven project and then imported it into eclipse ( file ->import -> existing maven projects)

The war gets deployed to tomcat 7 correctly.

However when I create a tomcat 7 server in Eclipse and then start tomcat in eclipse I get an exception when I run the application.

root cause

java.lang.NoClassDefFoundError: com/google/common/collect/ImmutableMap
    first.model.BeerExpert.<clinit>(BeerExpert.java:12)
    first.servlet.BeerServlet.doPost(BeerServlet.java:26)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.lang.ClassNotFoundException: com.google.common.collect.ImmutableMap
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    first.model.BeerExpert.<clinit>(BeerExpert.java:12)
    first.servlet.BeerServlet.doPost(BeerServlet.java:26)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

is there any specific class path setting that needs to be done in the eclipse/tomcat

Note: I am able to run mvn clean install and it creates the jar file. And then when I move the jar to a tomcat(7) webapp directory and restart it works just fine.

I am not posting details of the pom.xml because the application itself is working fine. However id it is needed in resolution I can post it.

SK176H
  • 1,319
  • 3
  • 14
  • 25

1 Answers1

46

Tomcat & Spring Web - Class Not Found Exception org.springframework.web.context.ContextLoaderListener

Right Click on your web project in Project Explorer -> select 'Properties'. Under project properties, select 'Deployment Assembly'.

The Deployment Assembly property page shows the content that will be published as a assembled artifact by Eclipse to the server. You need to tell Eclipse that you want all your Maven dependencies to be published too.

To do that, click 'Add' button, then select 'Java Build Path Entries'. Click Next and select Maven Dependencies. This will publish the Maven dependency JAR files to the lib folder when Eclipse publishes your project to WST server

Community
  • 1
  • 1
SK176H
  • 1,319
  • 3
  • 14
  • 25
  • Can we config this setting in pom file? – xi.lin Feb 27 '15 at 15:29
  • 4
    I had this same issue and could not figure out what was wrong for two days. I suppose my situation is very unique but I put it out there just in case. For the project that was not getting exported I went to Properties -> Project Facets and unchecked Utility Module. Did a clean on Tomcat and republished. That did it. I feel this was just some weird bug, but am adding just in case it can help someone. – DavidR Jul 15 '15 at 16:10
  • @DavidR, I've been struggling with this for 24 hours, and you seem to be the only person on the internet with the solution. Thank you! If you've tried the above without luck, give this a shot. – thomas88wp Oct 26 '16 at 19:20
  • 1
    Additionally, you might need to remove and re-add each of your project dependencies. Sometimes they're there but Eclipse says it can't find them. – thomas88wp Oct 16 '20 at 13:23