NoClassDefFoundError - Deserializers$Base

When running Java code that calls Scala, namely the Play library, I'm seeing this error when running the below test code.

java.lang.NoClassDefFoundError: org/codehaus/jackson/map/Deserializers$Base

I looked up Deserializers$Base to find out it's part of the package, org.codehaus.jackson. Then, I saw that this package is part of the jackson-mapper-asl artifactId.

Java

// Main
Foo foo = new Foo();
foo.do();  // <-- top of stack trace

public class Foo {
     public String do() {
        List<JsValue> jsonList = new ArrayList<JsValue>();
        // populate jsonList
        return JsonUtil.build(json); // <-- second line of stack trace
     }

Scala

object JsonUtil {
import collection.JavaConverters._
   def build(x: java.util.List[JsValue]): String = 
       Json.obj("bar" -> x.asScala.toList).toString
   }
}

After adding this dependency to my POM, I still encountered the above error. Full stack trace:

java.lang.NoClassDefFoundError: org/codehaus/jackson/map/Deserializers$Base
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at play.api.libs.json.JacksonJson$module$.setupModule(JsValue.scala:460)
    at org.codehaus.jackson.map.ObjectMapper.registerModule(ObjectMapper.java:444)
    at play.api.libs.json.JacksonJson$.<init>(JsValue.scala:464)
    at play.api.libs.json.JacksonJson$.<clinit>(JsValue.scala)
    at play.api.libs.json.Json$.stringify(Json.scala:48)
    at play.api.libs.json.JsValue$class.toString(JsValue.scala:79)
    at play.api.libs.json.JsObject.toString(JsValue.scala:158)
    at com.workspace.json.JsonUtil$.build(JsonUtil.scala:95)

Note that I've installed play_2.10-2.1.5 and play-iteratees_2.10-2.1.5 libraries using mvn install .... Additionally, I added the proper Jackson dependency, but again the above error showed up at run-time.

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

Answers


i think you're missing the slf4j-api (that's where it gave a compile issue for me with mvn compile). Also, you didn't need to localy install the version, all that was needed wat a repository added to your pom.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>stackoverflow</groupId>
    <artifactId>21489814</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <dependency.jackson-mapper-asl.version>1.9.13</dependency.jackson-mapper-asl.version>
        <dependency.play-java_2.10.version>2.1.5</dependency.play-java_2.10.version>
        <dependency.play-iteratees_2.10.version>2.1.5</dependency.play-iteratees_2.10.version>
        <dependency.slf4j.version>1.7.5</dependency.slf4j.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
        </dependency>
        <dependency>
            <groupId>play</groupId>
            <artifactId>play-java_2.10</artifactId>
        </dependency>
        <dependency>
            <groupId>play</groupId>
            <artifactId>play-iteratees_2.10</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-mapper-asl</artifactId>
                <version>${dependency.jackson-mapper-asl.version}</version>
            </dependency>
            <dependency>
                <groupId>play</groupId>
                <artifactId>play-java_2.10</artifactId>
                <version>${dependency.play-java_2.10.version}</version>
            </dependency>
            <dependency>
                <groupId>play</groupId>
                <artifactId>play-iteratees_2.10</artifactId>
                <version>${dependency.play-iteratees_2.10.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${dependency.slf4j.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <repositories>
        <repository>
            <id>TypesafeRepository</id>
            <name>Typesafe Repository</name>
            <url>http://repo.typesafe.com/typesafe/releases/</url>
            <layout>default</layout>
        </repository>
    </repositories>
</project>

I hope this helps.


Need Your Help

Simplest way to empty a database with ForeignKeys without deleting/creating it

php mysql database

I would like to empty a Mysql database (eg destroy all tables) . But: I don't have the permission to delete that database. So I can't use the trick

How to save my app settings?

c# windows uwp

I have a problem with saving my app settings? I creating windows 10 universal app and I have Slider which value I want to save.