0

I am using a jersey client to push data to the localhost. Here is my code -

public CloudConnection(JSONObject jsonPush) throws ClientProtocolException, IOException, JSONException {
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource webResource = client.resource(UriBuilder.fromUri("http://localhost/visual/savedata.php").build());
    ClientResponse response = webResource.path("restPath").path("resourcePath").type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, jsonPush);
}

When i execute this in Eclipse it works fine and the db on my localhost is inserted with a recoord using savedata.php. But as soon i make a runnable jar of my project and run the jar it throws error -

 a message body writer for java type, class org.codehaus.jettison.json.JSONObject, and MIME media type, application/json was not found

How can i make this work normally when executing from the runnable jar?

Dan
  • 701
  • 2
  • 11
  • 29
  • 1
    show your complete command line on how you are starting the application from you executable .jar –  Jul 23 '13 at 21:30

1 Answers1

1

You have to have the Jersey client .jar on the classpath of the exectuable .jar as well as the Jersey .jar.

If you are using Maven and you should be using Maven to build your artifacts, you can use the shade plugin and it will create an Uberjar of your code, and all the dependencies of your code in a single executable .jar file. Then you won't need to worry about specifying all the dependences and their transitive dependencies on the command line.