GionJh GionJh - 5 months ago 27
Java Question

Restlet and Jackson: java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonFactory

I'm trying to make Restlet work with Jackson in the following way:

public class HelloWorldResource extends ServerResource{
@Get("json")
public Todo represent()
{
Todo t = new Todo();
t.setId("1");
t.setDescription("hello");
t.setSummary("world");

return t;
}
//...
}


what I get is:


java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonFactory


These are the jars I'm using:

enter image description here

any help ?

EDIT:

I solved by adding to the classpath this jar.

I'm still interested to know if there are some mistakes/redundancies in the jars
I'm adding.

Answer

You should configure your application using Maven. That way, we will have automatically all required dependencies (included dependencies of dependencies transitively).

In your case, we could use something like that within your file pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>org.restlet</groupId>
    <artifactId>restlet-maven-sample</artifactId>
    <name>${project.artifactId}</name>
    <packaging>war</packaging>
    <version>1.0.0-snapshot</version>

    <properties>
        <restlet-version>2.3.1</restlet-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet</artifactId>
            <version>${restlet-version}</version>
        </dependency>

        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet.ext.jackson</artifactId>
            <version>${restlet-version}</version>
        </dependency>

        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet.ext.servlet</artifactId>
            <version>${restlet-version}</version>
        </dependency>

        <dependency>
            <groupId>org.restlet.jee</groupId>
            <artifactId>org.restlet.ext.xml</artifactId>
            <version>${restlet-version}</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>maven-restlet</id>
            <name>Public online Restlet repository</name>
            <url>http://maven.restlet.com</url>
        </repository>
    </repositories>
</project>

Hope it helps you, Thierry