I'm trying to make Restlet work with Jackson with the following Java code:
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;
}
//...
}
When I run the program I get an error:
java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonFactory
These are the jars I'm using:
Why can't it find the dependencies?
EDIT:
I solved the problem by adding this jar to the classpath.
I'm still interested to know if there are some mistakes/redundancies in the jars I'm adding.
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