0

I got a "mavenized" webapp project and i finally get my file .war After that, i got to deploy it in Tomcat 6 but i can't figure out the context, i got this error :

GRAVE: Erreur lors de la configuration de la classe d'écoute de l'application (application listener) application.util.SessionListener

java.lang.ClassNotFoundException: application.util.SessionListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4153)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4709)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:822)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1060)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
    at org.apache.catalina.core.StandardService.start(StandardService.java:525)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:759)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

The SessionListener class is implemented like this:

package application.util;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SessionListener implements HttpSessionListener {

    private final Log log = LogFactory.getLog(this.getClass());

    public void sessionCreated(HttpSessionEvent event) {
        log.debug("session créée : " + event.getSession().getId());
    }

    public void sessionDestroyed(HttpSessionEvent event) {
    }

}

web.xml

<!-- Spring intialisation -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>


    <listener>
        <listener-class>
            application.util.SessionListener
        </listener-class>
    </listener>

I configured the file context.xml of Tomcat with the appropriate connection to the DB. I use Tomcat 6 and also JDK 1.7

Hohenheim
  • 1,545
  • 1
  • 12
  • 28
  • 1
    The "application.util.SessionListener" class is not present. You must have it either in your application's classes or your application's libs, or in the server libs. – Arnaud Dec 23 '15 at 09:43
  • `application.util.SessionListener ` is something which is owned by your application code like some extension of `java.util.EventListener`? – Jay Dec 23 '15 at 09:47
  • I got it Under `src/main/java : SessionListener.java` and also when i compile the project i got the class Under `target\application-0.0.1-SNAPSHOT\WEB-INF\CLASSES: SessionListener.class` – Hohenheim Dec 23 '15 at 09:48
  • It's a class Under package `application.util` – Hohenheim Dec 23 '15 at 09:49
  • Have a look if this helps - http://stackoverflow.com/questions/6210757/java-lang-classnotfoundexception-org-springframework-web-context-contextloaderl – Jay Dec 23 '15 at 10:04
  • @Jay thnx but it's not the same problem in your post, he got a problem with the jar of spring but mine is with the class SessionListener.java – Hohenheim Dec 23 '15 at 10:16
  • Can you paste what SessionListener does? – Jay Dec 23 '15 at 10:19
  • Can it be that you had your application deployed already on tomcat before you introduced this new listener? and then you just dropped new war file after introducing the new war? If that is the case, try to have a clean deploy either using Tomcat Manager UI or stop the tomcat, delete your existing war file and exploded directory, drop new war file and start tomcat. – Jay Dec 23 '15 at 11:38
  • @Jay thnx for your reply, i did it but still `Error ListenerStart` :s – Hohenheim Dec 23 '15 at 13:18

1 Answers1

0

You probably have a declaration in your web.xml like this:

<web-app ...>
    <listener>
        <listener-class>application.util.SessionListener</listener-class>
    </listener>
</web-app>

This means that your SessionListener class (that you found in WEB-INF/classes) must be in the package application.util. E.g. the compiler needs to compile it to WEB-INF/classes/application/util/SessionListener.class (don't just move it there).

Alternatively change the declaration in web.xml to omit the application.util. part

Edit: I'm not sure how to read your comments - it might already be in that package. If this is indeed the case there's two more options:

  • Make extra extra extra sure that there's no typo in class or package name (it's easy to miss this with the web.xml declaration)
  • Check if your SessionListener class references other classes (e.g. as members) that it requires. If they are missing, the JVM can't instantiate an object of class SessionListener as well, resulting in similar problems.
  • Even (or especially) after your comments to this question: Please check the answer on Jay's link from the comments. Go through those steps. It might be a different jar that you're missing, but the underlying concepts are the same, no matter what the exact class is.
  • If that still doesn't help: Go through my suggestion from the comment: Eliminate the Log and LogFactory references just for a few minutes, try again. Even if it can't be this, it's better to have this ruled out by trying it out rather than by stating it "can't be".
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • thnx for your reply; that's my class SessionListener – Hohenheim Dec 23 '15 at 10:43
  • Thnx for updating i delete the answer – Hohenheim Dec 23 '15 at 10:46
  • Your listener references classes from `org.apache.commons.logging` - if they're not available, my second bulletpoint ("...references other classes...") would be valid. Remove those references and temporarily replace with `System.out.println` - this would rule out that possibility, or point you to the root cause. – Olaf Kock Dec 23 '15 at 10:52
  • i got the jar commons-logging-1.0.4.jar in Maven dependencies, if the project didn't recognize them i well probably get an eror in the code for this : import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; – Hohenheim Dec 23 '15 at 11:00
  • How do you add them to the maven dependencies? I've often seen the compiler happy about them, only they've not been available at runtime, so that tomcat couldn't find them. Check if the jar ends up in `WEB-INF/lib`, then you'll have it right. – Olaf Kock Dec 23 '15 at 11:02
  • i listed the jar as a dependecy in the pom.xml , and in the folder `target` i got Under `application-SNAPSHOT` the folder `WEB-INF\classes\application\util\SessionListener.class` – Hohenheim Dec 23 '15 at 11:07
  • i also found the jar commons Under `WEB-INF\lib` – Hohenheim Dec 23 '15 at 11:07
  • Hi @Olaf, sorry for my late answer, i tried it and i get an another exception, tried to to update the jar `commons` but i failed because the hierarchy dependency because he's dépendent to `lingo.jar`, i think i have to replace it but the `lingo.jar` i exported it because he's an internal lib to the project so i replace it or not ? – Hohenheim Dec 28 '15 at 10:10
  • Jay and @Olaf Happy Christmas btw ;) – Hohenheim Dec 28 '15 at 10:19
  • When i commented application.util.SessionListener – Hohenheim Dec 29 '15 at 16:39