views:

233

answers:

4

I'm trying to starting up with a Spring 2 + Struts 2 + Hibernate 3 arquitecture project, but I get an exception when deploy it in Apache Tomcat 6.0 within Eclipse (Helios version).

Tomcat's exception on start:

GRAVE: Error configurando escuchador de aplicación de clase org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4078)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
24-ago-2010 12:22:04 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Se ha saltado la instalación de escuchadores de aplicación debido a error(es) previo(s)
24-ago-2010 12:22:04 org.apache.catalina.core.StandardContext start
GRAVE: Error listenerStart
24-ago-2010 12:22:04 org.apache.catalina.core.StandardContext start
GRAVE: Falló en arranque del Contexto [/web] debido a errores previos

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="struts_blank" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
    <display-name>Struts Blank</display-name>

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

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring.xml</param-value>
    </context-param>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

I googled it for a long time, and I tried some possible solutions that I found but they haven't worked. I'm going to explain what I tried and the exception obtained:

First way: In Tomcat server configuration, classpath tab, I added spring-web-2.5.1.jar (just the same used in the project) as external jar in Bootstrap Entries section. Then when Apache triggers this exception when starts

GRAVE: Error configurando escuchador de aplicación de clase org.springframework.web.context.ContextLoaderListener
java.lang.NoClassDefFoundError: javax/servlet/ServletContextListener
    at java.lang.ClassLoader.findBootstrapClass(Native Method)
    at java.lang.ClassLoader.findBootstrapClass0(ClassLoader.java:900)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:314)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1560)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4078)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
24-ago-2010 12:42:36 org.apache.catalina.core.StandardContext listenerStart
GRAVE: Se ha saltado la instalación de escuchadores de aplicación debido a error(es) previo(s)
24-ago-2010 12:42:36 org.apache.catalina.core.StandardContext start
GRAVE: Error listenerStart
24-ago-2010 12:42:36 org.apache.catalina.core.StandardContext start
GRAVE: Falló en arranque del Contexto [/web] debido a errores previos

So I added, in the same place and way, servlet-api-2.4.jar. Then I get the following exception:

INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getContextPath()Ljava/lang/String;
    at org.apache.catalina.core.StandardHost$MemoryLeakTrackingListener.lifecycleEvent(StandardHost.java:561)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4625)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    ... 6 more

Second way: In classpath tab I add my project and I get the same exception posted earlier (java.lang.reflect.InvocationTargetException).

Why doesn't Apache Tomcat read properly the project libraries? Maybe I'm overlooking something, or something is wrong at all. Could you please help me to solve it? I'll give all information you need for it.

Any help will be welcome.

A: 

org.springframework.web.context.ContextLoaderListener check this by putting in classs import... if not available than add appropriate jar..

taher
You're right, but when I include it on classpath, I get another exception as I told in the message. Thanks for your reply
CraicFinder
A: 

You can't just add spring-web-2.5.1.jar on its own, you need a bunch of the other Spring JARs to go along with it, e.g. spring-core, spring-beans, spring-context, spring-context-support, and maybe spring-webmvc. Better yet, play it safe and use the all-in-one spring.jar.

Oh, and Spring 2.5.1 is ancient. At least upgrade to 2.5.6, or preferably 3.0.x.

skaffman
I'm just including all the libraries as it's explained in second way, but it isn't still working. Thanks for your reply
CraicFinder
A: 

There is a problem deploying jar files from Eclipse to Tomcat. I'm sure there is a better way to solve it, while I found it I solved it generating the war file and deploying it on a standalone installation of Apache Tomcat.

CraicFinder
A: 

You cannot include servlet-api jar inside a tomcat web app. try removing it.

anony.mouse