12

I'm using Spring Tool Suite 3.1 and I have some issues deploying a web application to tomcat.

When I hit "run on server" and the server starts it throws the famous:

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

So I check the /wtpwebapps directory to find that the project is deployed, but inside the lib folder only a few libraries are present. I completely miss the rationale behind their selection. Of course the libraries related to spring aren't there. Can anyone help?

This is my org.eclipse.wst.common.commonent file, maybe it can be useful:

<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="Checkup">
    <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
    <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
    <property name="context-root" value="Checkup"/>
    <property name="java-output-path" value="/Checkup/build/classes"/>
</wb-module>

EDIT:

you can see the list of maven plugin embedded with STS installation (no customizations)

STS maven plugins

MaVVamaldo
  • 2,505
  • 7
  • 28
  • 50
  • Does the STS include, or are you using, a maven plugin? – Dave Newton Oct 17 '12 at 10:03
  • you can see the plugin specification as EDITed in the question – MaVVamaldo Oct 17 '12 at 11:20
  • possible duplicate of [java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener](http://stackoverflow.com/questions/6210757/java-lang-classnotfoundexception-org-springframework-web-context-contextloaderl) – NimChimpsky Oct 17 '12 at 11:40

4 Answers4

37

add maven dependencies to deployment assembly, by right clicking project - navigating to deployment assembly, and then adding the maven dependencies library.

NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • 5
    any particular reason for downvote, as this solved excatly the same problem I had in eclipse wtp (not sts) – NimChimpsky Oct 17 '12 at 10:23
  • To check my deployment assembly was my first guess, but everything seems alright: the maven dependencies are there and map to the WEB-INF/lib folder. – MaVVamaldo Oct 17 '12 at 11:19
  • IIRC in a Maven web project the dependencies are *already* added to the deployment. I've never had to do anything special to create a deployable artifact. Moreover, inside Eclipse, an assembly isn't created when it runs on server, since then even a JSP change would trigger a complete packaging including tests etc. – Dave Newton Oct 17 '12 at 11:32
  • @DaveNewton I have had to manually add the maven lib more than one occasion, and others have to : http://stackoverflow.com/a/8128255/106261 – NimChimpsky Oct 17 '12 at 11:37
  • Oh, I thought you meant as a Maven assembly. – Dave Newton Oct 17 '12 at 11:45
  • @maVVamaldo I think this is yr problem, are you sure you specify the maven lib correctly. As the error is caused by not having spring jar available when tomcat deploys app... – NimChimpsky Oct 17 '12 at 11:55
  • @NimChimpsky I really don't know how to check if my maven dependencies are correctly specified. I let the IDE to add them as I intercat with the "Deployment Assembly" window. – MaVVamaldo Oct 17 '12 at 12:40
  • Thanks, helped me a lot. Don't know why this deployment dependency was missing with my project. – Matthias Wuttke Apr 13 '13 at 07:05
17

after hours of pain it seems the problem is solved thanks to magics or something. The "mysterious" procedure that fixed the things is the following:

  1. run your project on tomcat and get the error
  2. clean tomcat rclick ---> clean (not clean working directory) while your project is still on the server
  3. run the server again

the tricky part is cleaning tomcat when the web app is still deployed. I really don't know why it works. If you stop the server, remove the application, clean the server and redeploy the application again you get the error. I won't dare to understand further, I accept the mystery.

MaVVamaldo
  • 2,505
  • 7
  • 28
  • 50
  • 1
    I don't know how or why but this also worked for me. Deployment Assembly had Maven Dependencies already added with a target of 'WEB-INF/lib' but it wasn't working. I tried this and it worked. Thanks. – dangerisgo May 19 '18 at 07:46
2

NimChimpsky's answer is right solution for me. Only it's not very specific. The detailed steps is: right click project -> select "properties" -> search "Deployment Assembly" -> click "Add" button -> add "Maven Dependent"

Jianwu Chen
  • 5,336
  • 3
  • 30
  • 35
1

Another way to fix this issue is by using the terminal (Linux or Mac) or the command prompt (Windows). Navigate to the folder of the project and use the following command:

mvn eclipse:eclipse -Dwtpversion=2.0

Once the command is successfully executed, a new file called org.eclipse.wst.common.component will be created inside the .settings folder of the project.

Start the server and it should pick all the dependent libraries automatically.