users@jersey.java.net

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

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Tue, 05 Apr 2011 09:52:33 +0200

Hello Adam,

you need to pul
http://download.java.net/maven/2/javax/ws/rs/jsr311-api/1.1.1/jsr311-api-1.1.1.jar
on your classpath.

You might want explore some samples to get working "tutorials":
http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.6/jersey-samples-1.6-project.zip

Regards,
Pavel

On 04/04/2011 09:08 PM, Adam Ray wrote:
>
> 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
>