I am doing some basic spring stuff and stuck at some point.
I am getting ClassNotFoundException
whenever I deploy my application on Tomcat.
I observed
Put your jars in the WEB-INF/lib
directory:
In Project properties -> Deployment Assembly you should have a Source of /web
with a Deployment Path of /
. If this is there then any jars in the web/WEB-INF/lib
directory will get deployed and picked up by the class loader. Note that sub-directories will not be picked up though, so put your jars directly in the lib directory.
If you define "war" packaging for your maven project then your dependent libraries should be automatically copied to the WEB-INF/lib
directory of the created .war file by the Maven WAR plugin.
You run three command in cmd or bash(where your pom.xml file placed) to get jar file and copy it into your WEB-INF/lib folder
mvn compile
mvn package
mvn install
I find only this way for resolved my problem:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Go to "Project properties -> Deployment Assembly page".
This page describes how your application will be packaged for deployment or export. And added new source "Maven dependency".
From Deployment Assembly page, Click Add... button Then select "Java Build Path Entries" "Maven dependency" should be in the list
It solves the issue and all jar got copied to tomcat