users@jersey.java.net

Provider not getting detected properly

From: Chris Carrier <ctcarrier_at_gmail.com>
Date: Mon, 1 Feb 2010 17:31:07 -0800

OK so I have a very strange problem that I don't have a good solution
for so I'm hoping someone can shed some light on it. I'm creating
JSON services and letting JAXB handle the marshalling. This works
fine when I run my code via my IDE (IntelliJ). It runs the code
directly via my main() method. The problem is when I package the code
into a jar and try to run on the command line I get an error:

SEVERE: A message body writer for Java type, class com.some.Class, and
MIME media type, application/json, was not found

This is 100% consistent. I run in the IDE and it works then I try
with the JAR and it explodes. I added a log line like this:

log.info("PROVIDERS " +
ps.getMessageBodyWriter(RedirectLinkCollection.class, null, null,
MediaType.APPLICATION_JSON_TYPE));

And sure enough in the IDE it prints:

PROVIDERS com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App_at_1925d92

While from the JAR it prints:

PROVIDERS null

Any ideas? I'm bundling all dependencies directly into my JAR and I
can attest to the fact that the class is in there. I can work around
this by writing my own JSON writer but I would rather leverage the
JAXB automagic stuff.

Chris