Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Jersey客户端获取错误_Java_Json_Service_Jersey Client - Fatal编程技术网

Java 使用Jersey客户端获取错误

Java 使用Jersey客户端获取错误,java,json,service,jersey-client,Java,Json,Service,Jersey Client,我正在使用jersey客户端将数据推送到本地主机。这是我的密码- public CloudConnection(JSONObject jsonPush) throws ClientProtocolException, IOException, JSONException { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource

我正在使用jersey客户端将数据推送到本地主机。这是我的密码-

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);
}
当我在Eclipse中执行此操作时,它工作正常,并且使用savedata.php插入本地主机上的db,并使用recoord。但当我为我的项目制作一个可运行的jar并运行jar时,它就会抛出错误-

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

当从可运行jar执行时,如何使其正常工作?

您必须将Jersey client.jar放在exectuable.jar和Jersey.jar的
类路径上


如果您正在使用Maven,并且应该使用Maven来构建您的工件,那么您可以使用
shade
插件,它将在单个可执行的.jar文件中创建代码的
Uberjar
,以及代码的所有依赖项。这样,您就不必担心在命令行上指定所有依赖项及其可传递依赖项。

显示有关如何从可执行文件.jar启动应用程序的完整命令行