Announcement Announcement Module
Collapse
No announcement yet.
java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper

    I'm trying to develop an application where I would like to use org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter class to convert javabeans to json.

    The case is I'd like use declarative options in app-servet-xml.

    When I start the server I get following exception:

    PHP Code:
    javax.servlet.ServletExceptionServlet.init() for servlet objectverse threw exception
        org
    .apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        
    com.springsource.server.web.tomcat.ApplicationNameTrackingValve.invoke(ApplicationNameTrackingValve.java:37)
        
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
        
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
        
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
        
    java.lang.Thread.run(Thread.java:619)

    root cause

    org
    .springframework.beans.factory.BeanCreationExceptionError creating bean with name 'jsonHttpMessageConverter' defined in ServletContext resource [/WEB-INF/objectverse-servlet.xml]: Instantiation of bean failednested exception is org.springframework.beans.BeanInstantiationExceptionCould not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exceptionnested exception is java.lang.NoClassDefFoundErrororg/codehaus/jackson/map/ObjectMapper
        org
    .springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
        
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:890)
        
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
        
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
        
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
        
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
        
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
        
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
        
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
        
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
        
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
        
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
        
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
        
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
        
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
        
    javax.servlet.GenericServlet.init(GenericServlet.java:212)
        
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        
    com.springsource.server.web.tomcat.ApplicationNameTrackingValve.invoke(ApplicationNameTrackingValve.java:37)
        
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
        
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
        
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        
    org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
        
    java.lang.Thread.run(Thread.java:619
    Why?

    My app-servlet.xml looks like
    PHP Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:beans="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
            
        <!-- Configures the @Controller programming model -->
        <mvc:annotation-driven />
        
        <!-- enable classpath scanning -->
        <context:component-scan base-package="objectverse.web" />
        
        <bean id="jsonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" >
            <property name="supportedMediaTypes" value="application/json" />    
        </bean>  
        
        <!--
        Maps incoming requests to the appropriate controller based on the annotations on
        the controller methods.
        -->
        <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
        <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
            <property name="messageConverters">
                <util:list id="beanList">  
                    <ref bean="jsonHttpMessageConverter" />  
                </util:list> 
            </property>
        </bean>
        
        <!-- configure FreeMarker support -->
        <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
            <property name="templateLoaderPath" value="/WEB-INF/ftl/" />
        </bean>

        <bean id="viewResolver"    class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
            <property name="cache" value="true" />
            <property name="suffix" value=".ftl" />
        </bean>
        
    </beans>
    My pom.xml
    PHP Code:
    ...
        <
    dependencies>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>org.springframework.spring-library</artifactId>
                <
    type>libd</type>
                <
    scope>provided</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>spring-webmvc</artifactId>
                <
    scope>provided</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>org.springframework.web</artifactId>
                <
    version>${org.springframework-version}</version>
                <
    type>pom</type>
                <
    scope>compile</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>org.springframework.expression</artifactId>
                <
    version>${org.springframework-version}</version>
                <
    type>pom</type>
                <
    scope>compile</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.freemarker</groupId>
                <
    artifactId>com.springsource.freemarker</artifactId>
                <
    scope>compile</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>javax.servlet</groupId>
                <
    artifactId>com.springsource.javax.servlet</artifactId>
                <
    scope>provided</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.junit</groupId>
                <
    artifactId>com.springsource.org.junit</artifactId>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>org.springframework.test</artifactId>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>org.springframework.aspects</artifactId>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.springframework</groupId>
                <
    artifactId>org.springframework.instrument</artifactId>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.apache.commons</groupId>
                <
    artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>com.h2database</groupId>
                <
    artifactId>com.springsource.org.h2</artifactId>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.aspectj</groupId>
                <
    artifactId>org.aspectj-library</artifactId>
                <
    type>libd</type>
                <
    scope>test</scope>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.codehaus.jackson</groupId>
                <
    artifactId>jackson-mapper-asl</artifactId>
                <
    version>1.6.0</version>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.joda</groupId>
                <
    artifactId>com.springsource.org.joda.time</artifactId>
                <
    version>1.6.0</version>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.codehaus.jackson</groupId>
                <
    artifactId>com.springsource.org.codehaus.jackson</artifactId>
                <
    version>1.4.3</version>
            </
    dependency>
            <
    dependency>
                <
    groupId>org.codehaus.jackson</groupId>
                <
    artifactId>com.springsource.org.codehaus.jackson.mapper</artifactId>
                <
    version>1.4.3</version>
            </
    dependency>         
        </
    dependencies>
    ... 
    Best regards,
    Bojan

  • #2
    I'm facing the same problem. Could not solve it even by adding direct dependencies in the pom.xml.

    I checked dmServer console, the imported package org.codehaus.jackson.map is resolved, found in the jackson mapper bundle i uploaded into dmServer. If i change the version, my webapp bundle refresh fails for missing constraint, as expected, so it actually succeeds to resolve the package import.

    So i don't know where he fails to find the class that should be imported by the package. I tried import-package first, then changed to import-bundle, and nowi have even more packages imported from jackson mapper bundle (as expected), but still i have this NoClassDefFound error on org/codehaus/jackson/map/ObjectMapper.

    I would really appreciate help on this, i'm stuck, cannot get Ajax working (and if i don't use json, i get a 406 Not Acceptable http error, so i don't even have a workaround for this problem).

    Anyone has a an idea?

    Comment


    • #3
      Hi there.
      I faced the same problem. I managed to figure it out.
      Actually i was providing jackson bundles version 1.4.3
      The spring bundle org.springframework.web_3.0.0.RELEASE was importing jackson packages with an optional resolution (which explain it didn't fail to load), but the range of version expected for jackson packages is [1.0.0, 1.1.0), which does not match the 1.4.3 i was providing.

      I saw in your pom that you provide the exact same version, 1.4.3. Just download jackson 1.0.0 bundles from spring enterprise bundle repository and your webapp will start successfully.

      Comment


      • #4
        Thanks. I'll try it out.
        I've also found out that I probably need to use .json extension, that content negotiation will work as expected.
        -----
        OK. I can not post another reply.
        This didn't help. I still get this error. I tried everithing that I know.

        I constantly get:
        Allocate exception for servlet objectverse java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
        Last edited by bkraut; Nov 18th, 2010, 06:41 AM.

        Comment

        Working...
        X