users@jersey.java.net

[Jersey] No message body writer for String... but works in Eclipse

From: tendancer <tendancer_at_gmail.com>
Date: Thu, 20 Jan 2011 10:05:54 -0800 (PST)

I have a Jersey resource that returns "hello world" as a String and when I
run my application from Eclipse using Run As... I can send the request and
receive the string. However, when I bundle my app into a jar file and run it
on the command line using java --jar (the Main class launches an embedded
Jetty server) I get:

SEVERE: A message body writer for Java class java.lang.String, and Java type
class java.lang.String, and MIME media type text/plain was not found

I have about 60 resource methods that return JSON objects and they all work
fine on the command line, just this one String method that does not. I use
Guice for my bindings:

bind(MessageBodyReader.class).to(JacksonJsonProvider.class);
bind(MessageBodyWriter.class).to(JacksonJsonProvider.class);

I'm tempted to think it a pom file issue, that something that should be in
the dependent jar is not getting put there, otherwise why would it work in
Eclipse? I'm totally stuck, anyone with any suggestions would be greatly
appreciated. Here's the some of the pom file in case it helps.

<dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty</artifactId>
        <version>6.1.25</version>
</dependency>
<dependency>
        <groupId>com.google.inject</groupId>
        <artifactId>guice</artifactId>
        <version>2.0</version>
</dependency>
<dependency>
        <groupId>com.google.inject.extensions</groupId>
        <artifactId>guice-servlet</artifactId>
        <version>2.0</version>
</dependency>
<dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>r07</version>
</dependency>
<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-server</artifactId>
        <version>1.3</version>
</dependency>
<dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-guice</artifactId>
        <version>1.3</version>
</dependency>
<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-json</artifactId>
        <version>1.3</version>
</dependency>
<dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.5.4</version>
</dependency>
<dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.5.4</version>
</dependency>
<dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-jaxrs</artifactId>
        <version>1.5.4</version>
</dependency>

Cheers

Paul.
-- 
View this message in context: http://jersey.576304.n2.nabble.com/No-message-body-writer-for-String-but-works-in-Eclipse-tp5944778p5944778.html
Sent from the Jersey mailing list archive at Nabble.com.