title: Jersey client, JAXBContext used when application is executed with Maven, but not with java -jar
body: <p>I'm implementing a rest client consuming json data using the Jersey Client API. I don't really have much experience with JAXB, and especially not in combination with JSON. I've followed the example provided <a href="https://blogs.oracle.com/enterprisetechtips/entry/consuming_restful_web_services_with" rel="nofollow noreferrer">here</a> and registered a JAXBContext. </p>
  
  <p>Everything works like a charm when I execute the project using <code>mvn exec:java</code>. </p>
  
  <p>I use the Maven assembly plugin to create a single JAR. When I use this JAR file to run the client the JAXBContext does not appear to be used at all. Which results in:</p>
  
  <p><em>"com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class org.digitest.model.Account, and Java type class org.digitest.model.Account, and MIME media type application/json was not found"</em></p>
  
  <p>Does anyone has any idea when I might be doing wrong? Even vague tips on how to proceed with debugging will be greatly appreciated! </p>
  
  <pre><code>@Provider
  public final class ModelJAXBContextResolver implements ContextResolver&lt;JAXBContext&gt; {
  
      private final JAXBContext context;
      private final Set&lt;Class&gt; types;
      private final Class[] cTypes = {
          Account.class, ...
      };
  
      public ModelJAXBContextResolver() throws Exception {
          this.types = new HashSet(Arrays.asList(cTypes));
          this.context = new JSONJAXBContext(JSONConfiguration.natural().build(), cTypes);
          throw new Exception("Json context is loaded");
      }
  
   @Override
      public JAXBContext getContext(Class&lt;?&gt; objectType) {
          return (types.contains(objectType)) ? context : null;
      }
  
  }
  </code></pre>
  
  <p>Client setup:</p>
  
  <pre><code>DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
  config.getProperties().put(DefaultApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, true);
  config.getClasses().add(ModelJAXBContextResolver.class);
  
  client = ApacheHttpClient.create(config);
  </code></pre>
  
  <p>Account:</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class Account {
      ...
  }
  </code></pre>