Class NotFoundException with ServletContextlistener

I get an exception when I try to get the context parameter from we.XML into the ServletContextListener class, it is really hard for me to understand why it does not work, here is the exception in Apache Tomcat 7.0.11 log:

  Oct 21, 2011 1:24:23 PM org.apache.catalina.core.StandardContext listenerStart SEVERE: Error configuring application listener of class alaa.ServletContextListener java.lang.ClassNotFoundException: alaa.ServletContextListener at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415) at at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4618) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184) at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) 

Here is part of my web.xml:

  <context-param> <param-name>catName</param-name> <param-value>meshmesh</param-value> </context-param> <context-param> <param-name>catBreed</param-name> <param-value>egyptian</param-value> </context-param> <listener> <listener-class>alaa.CatLisenter</listener-class> </listener> <session-config> <session-timeout> 30 </session-timeout> </session-config> 

Here is my ServletContextListener.java:

 package alaa; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class CatLisenter implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); String name = sc.getInitParameter("catName"); String breed = sc.getInitParameter("catBreed"); Cat maCat = new Cat(); maCat.setName(name); maCat.setBreed(breed); sc.setAttribute("cat", maCat); } @Override public void contextDestroyed(ServletContextEvent sce) { throw new UnsupportedOperationException("Not supported yet."); } } Here Cat.java : package alaa; public class Cat { private String name; private String breed; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getBreed() { return breed; } public void setBreed(String breed) { this.breed = breed; } } many thanks 
+6
source share
6 answers

Try cleaning the tomcat working directory and cleaning it. After that, publish your project and run it again.

+7
source

I assume that you packed the servlet-api file into the webapp folder (in WEB-INF / lib), and this causes conflicts, since servlet-api is already present in the container. Make sure that you do not include any servlet-api or jsp-api frames (or Java EE api) in your webapp when you try to deploy it.

+5
source

I had the same problem running JUnit on Tomcat 7, and I decided that it adds the dependency to maven (pom.xml) as follows:

  <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-servlet-api</artifactId> <version>7.0.54</version> <scope>provided</scope> </dependency> 
+1
source

If you work in Eclipse then just clean up the project.

Follow this simple step, Go to Project> clean ...> clean all projects> Ok

+1
source

I had the same problem when I tried to use the LUNA version for eclipse and tomcat 7. The same code worked without any additional changes in eclipse JUNO with tomcat 7.

0
source

Check disk space . When eclipse copies the libs folder, if there is no disk space, this error may occur

0
source

Source: https://habr.com/ru/post/899786/


All Articles