users@jersey.java.net

[Jersey] Re: Could not initialize class MediaTypes

From: Kevin Duffey <andjarnic_at_yahoo.com>
Date: Thu, 30 Jun 2011 23:12:45 -0700 (PDT)

I am not for sure.. but is the JSR-311 library you are using up to date? Possible that if it's not the MediaType class is not in the version you are using, hence the ClassNotFound.. or if it is, you don't have it in your WEB-INF/lib in the WAR file you deploy. I guess it depends on the server you're deploying to. I deploy to GlassFish v3.1 and I only bundle the Jersey 1.7 (not using 1.8 yet). There is an issue with Glassfish anyway..because it comes bundled with Jersey 1.5, in order to use 1.6 or later, you have to set a JVM config option for it to find the jersey classes in your WAR web-inf/lib path. Hopefully something of this helps you.


--- On Thu, 6/30/11, jimbeard_at_uoregon.edu <jimbeard_at_uoregon.edu> wrote:

From: jimbeard_at_uoregon.edu <jimbeard_at_uoregon.edu>
Subject: [Jersey] Could not initialize class MediaTypes
To: users_at_jersey.java.net
Date: Thursday, June 30, 2011, 3:39 PM

Hello all,

I am trying to use the Jersey client and am running into some issues.
I have a simple class:


public class Demo {

  public static void main(String [] args) {

    System.out.println("Line 1: "+args[0]);

    ClientConfig config = new DefaultClientConfig();

    Client client = Client.create(config);

    client.addFilter(new HTTPBasicAuthFilter("login", "password"));
    WebResource webResource = client.resource("http:// ");

    MultivaluedMap<String, String>  queryParams = new
MultivaluedMapImpl();
    queryParams.add("r25_username", args[0]);
    String s =
webResource.queryParams(queryParams).delete(String.class);
    System.out.println("First output: " + s);

    ClientResponse response =
webResource.queryParams(queryParams).delete(ClientResponse.class,
queryParams);
    System.out.println("Second output: " + response.toString());
  }


}

Which I am compiling against jersey-bundle-1.8.jar and
jsr311-api-0.9.jar.  It compiles fine but when I try to run it I get :


Exception in thread "main" java.lang.NoClassDefFoundError: Could not
initialize class com.sun.jersey.core.header.MediaTypes
    at
com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageB
odyFactory.java:182)
    at
com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageB
odyFactory.java:176)
    at
com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFact
ory.java:162)
    at com.sun.jersey.api.client.Client.init(Client.java:342)
    at com.sun.jersey.api.client.Client.access$000(Client.java:118)
    at com.sun.jersey.api.client.Client$1.f(Client.java:191)
    at com.sun.jersey.api.client.Client$1.f(Client.java:187)
    at
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    at com.sun.jersey.api.client.Client.<init>(Client.java:187)
    at com.sun.jersey.api.client.Client.<init>(Client.java:170)
    at com.sun.jersey.api.client.Client.create(Client.java:679)
    at Demo.main(Demo.java:20)


Any idea what is going wrong here?

Thanks!