Woops meant to send this to the list:
Are you using the shade plugin to package your jar? I had this
problem and it was caused by the Jersey config files getting
overwritten because there were files with the same name coming from
multiple dependencies. I fixed it by replacing the old package plugin
with something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>path.to.main.Class</mainClass>
</transformer>
</transformers>
<outputFile>
${project.build.directory}/${project.build.finalName}-jar-with-dependencies.jar
</outputFile>
</configuration>
</execution>
</executions>
</plugin>
Obviously I've got spring stuff there so remove that if you don't use
it. This should help with conflicting resources.
On Thu, Jan 20, 2011 at 10:05 AM, tendancer <tendancer_at_gmail.com> wrote:
>
> 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.
>