users@jersey.java.net

[Jersey] Jersey client class loader issue

From: Noah White <emailnbw_at_gmail.com>
Date: Tue, 22 May 2012 18:47:36 -0400

Hi folks,

I'm trying to include Jersey client (1.11) APIs into my application. My application classes are packaged in a JAR w/a Manifest. When I run the jar with 'java -jar' and specify all the Jersey client dependent JARs in the cmd line's classpath arg list it all works fine.

Now I wanted to simplify deployment down to one single JAR so I configured my IDEA project to explode all the dependent JARs into the top level of my JAR so its structure looks something like this:

application.jar
    - org
    - META-INF
    - javax
    - com <- The MAIN class pointed to by the MANIFEST is in this folder
    - ch
    logback.xml


When I run it using that jar with: 'java -jar application.jar' it runs fine up until the point that I invoke a webResource which has an entity class. For example:

Foo myFoo = webResource.type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(Foo.class);

When that call is made I'll get:

SEVERE: A message body reader for Java class com.bar.Foo, and Java type class of com.bar.Foo, and MIME media type application/json was not found

blah blah blah

I've tried this using JAXB JSON mapping and the simple Jackson based POJO mapping and I get the same results. It works when the dependent JARs are separate from the application JAR and listed on the java cmd line class path but not when everything is exploded into one jar.

Interestingly I tried using one-jar [1] which keeps all the dependancies packaged in their original JARs but rolls them into your applications JAR and plays classloader tricks to load things up. In that case the application works fine. However, I don't really want to have to add one-jar to the mix if I don't have to. I'm not sure why the exploded method does not work but I have the suspicion its classloader related.

Any thoughts?

-Noah

[1] - http://one-jar.sourceforge.net/