users@jersey.java.net

[Jersey] Nothing to complicated: Consume REST help. Please help!

From: Adam Ray <adamray24_at_googlemail.com>
Date: Mon, 4 Apr 2011 20:08:32 +0100

Hi,


Please help!


I am following the tutorial here (Well written and simple to follow):


http://blogs.sun.com/enterprisetechtips/entry/consuming_restful_web_services_with#regp


<http://blogs.sun.com/enterprisetechtips/entry/consuming_restful_web_services_with#regp>

Which has lead to this code (Appologies for the class name):


*import* com.sun.jersey.api.client.Client;

*import* com.sun.jersey.api.client.config.ClientConfig;

*import* com.sun.jersey.api.client.config.DefaultClientConfig;

*import* com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider;



*public* *class* yutryt

{

    *public* *static* *void* main(String args[])

    {

         ClientConfig config = *new* DefaultClientConfig();

         config.getClasses().add(JSONRootElementProvider.*class*);

         Client *client* = Client.*create*(config);

    }

}


When I run, I get the following error (Iíve imported jersey-bundle-1.6.jar,
and nothing else)


Exception in thread "main" java.lang.NoClassDefFoundError:
javax/ws/rs/ext/MessageBodyReader

      at java.lang.ClassLoader.defineClass1(*Native Method*)

      at java.lang.ClassLoader.defineClassCond(Unknown Source)

      at java.lang.ClassLoader.defineClass(Unknown Source)

      at java.security.SecureClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.access$000(Unknown Source)

      at java.net.URLClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(*Native Method*)

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.defineClass1(*Native Method*)

      at java.lang.ClassLoader.defineClassCond(Unknown Source)

      at java.lang.ClassLoader.defineClass(Unknown Source)

      at java.security.SecureClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.access$000(Unknown Source)

      at java.net.URLClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(*Native Method*)

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.defineClass1(*Native Method*)

      at java.lang.ClassLoader.defineClassCond(Unknown Source)

      at java.lang.ClassLoader.defineClass(Unknown Source)

      at java.security.SecureClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.access$000(Unknown Source)

      at java.net.URLClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(*Native Method*)

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.defineClass1(*Native Method*)

      at java.lang.ClassLoader.defineClassCond(Unknown Source)

      at java.lang.ClassLoader.defineClass(Unknown Source)

      at java.security.SecureClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.defineClass(Unknown Source)

      at java.net.URLClassLoader.access$000(Unknown Source)

      at java.net.URLClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(*Native Method*)

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at yutryt.main(*yutryt.java:11*)

Caused by: *java.lang.ClassNotFoundException*:
javax.ws.rs.ext.MessageBodyReader

      at java.net.URLClassLoader$1.run(Unknown Source)

      at java.security.AccessController.doPrivileged(*Native Method*)

      at java.net.URLClassLoader.findClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

      at java.lang.ClassLoader.loadClass(Unknown Source)

      ... 49 more


Do I need to go through this:


http://jersey.java.net/nonav/documentation/latest/getting-started.html

To consume REST through Java? I'm not trying to setup a REST service, just
connect to one and use it.


Thank you for any help, Iíve trawled most of Google and spent around 6 hours
looking for a solution to this error.

Now of to buy this (http://oreilly.com/catalog/9780596158057)


Any help would be massively appreciated, I donít have long left to access
the API and want to show my work examples of what can be done.


THANK YOU!!!



Adam