users@jersey.java.net

[Jersey] Running from eclipse work but not from jar after ant build

From: Timothy Dewin <Timothy.Dewin_at_iriscorporate.com>
Date: Wed, 7 Mar 2012 13:07:52 +0000

Hi,

If I run a project from eclipse, the jersey api work perfect. However if I build a jar with my ant build script I always get this error

--------------
com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl, and MIME media type, application/x-www-form-urlencoded, was not found
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
at com.sun.jersey.api.client.filter.HTTPBasicAuthFilter.handle(HTTPBasicAuthFilter.java:81)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:568)
at eu.ondit.york.controllers.SyncController.getObject(Unknown Source)
at eu.ondit.york.controllers.SyncController.uploadXML(Unknown Source)
at eu.ondit.york.controllers.SyncController.post(Unknown Source)
at eu.ondit.york.controllers.SyncController.moveData(Unknown Source)
at eu.ondit.york.controllers.MainController.moveData(Unknown Source)
at eu.ondit.york.jobs.SyncerJob.execute(Unknown Source)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl, and MIME media type, application/x-www-form-urlencoded, was not found
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:288)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:204)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:147)
... 13 more

-----------------
Probably generated by the following code
MultivaluedMap<String, String> form = new MultivaluedMapImpl();
form.add("namespace", namespace);
form.add("object", object);

DataObject fetched = service.path("getobject").type(MediaType.APPLICATION_FORM_URLENCODED).post(DataObject.class,form);

------------------

My buildscript has the following jar part
<jar destfile="${compile.dir}/${file.name}"
basedir="${build.dir}">
<zipgroupfileset dir="${lib.dir}" includes="*.jar"/>
   <manifest>
     <attribute name="Main-Class"
           value="eu.ondit.york.Loader"/>
   </manifest>
</jar>

where lib.dir is the directory that contains all the jersey jar like jersey-client-1.12.jar . I suspect it has something to do with classloading but have no idea how to fix this.



TIA

Kind regards,
Timothy