我已经创建了一个Java程序来使用javax.ws.rs.client使用剩余的API对象。它工作得很好。但是当我创建jar文件并尝试运行jar文件时,它会搜索“ Exception:Org .glassfish.jersey.message.internal.MessageBodyProviderNotFoundException:MessageBodyWriter ....“
我试图添加所有我在build.xml中使用的jar文件,以使其可用并打包在将要构建的jar文件中
package gui;
import com.bean.BulkUserBean;
import javax.ws.rs.ClientErrorException;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import com.bean.ImageBean;
import com.bean.UserBean;
import java.util.ArrayList;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
//import javax.ws.rs.core.MediaType;
/**
*
* @author SPEED
*/
public class NewJerseyClient {
private WebTarget webTarget;
private Client client;
private static final String BASE_URL = "http://192.168.1.42:8080/ImageUpload/control";
// private static final String BASE_URL = "http://35.200.234.184/ImageUpload/control";
public NewJerseyClient() {
System.out.println("Hello --");
/* client = javax.ws.rs.client.ClientBuilder.newClient();
webTarget = client.target(BASE_URI);
*/ System.out.println("Hello");
client = ClientBuilder.newClient();
}
public UserBean getUser(String id) throws ClientErrorException {
WebTarget webTarget = client.target(BASE_URL).path("user").path(id);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
UserBean user = response.readEntity(UserBean.class);
System.out.println(response.getStatus());
System.out.println(user.getName());
return user;
}
public UserBean[] getUser() throws ClientErrorException {
System.out.println("Url " + BASE_URL);
WebTarget webTarget = client.target(BASE_URL).path("user");
System.out.println("Url " + BASE_URL);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
Response response = invocationBuilder.get();
UserBean[] user = response.readEntity(UserBean[].class);
System.out.println(response.getStatus());
return user;
}
public String translate() throws ClientErrorException {
return webTarget.path("sample").request().post(null, String.class);
}
public BulkUserBean getUserList(int offset, int limit) throws ClientErrorException {
System.out.println("Url " + BASE_URL);
WebTarget webTarget = client.target(BASE_URL).path("userList");
System.out.println("Url " + BASE_URL);
Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
//Response response = invocationBuilder.get();
//Response response = invocationBuilder.post(Entity.entity(new BulkUserBean(offset, limit), MediaType.APPLICATION_JSON));
BulkUserBean b = new BulkUserBean();
b.setOffset(offset);
b.setLimit(limit);
Response response = invocationBuilder.post(Entity.entity(b, MediaType.APPLICATION_JSON));
BulkUserBean user = response.readEntity(BulkUserBean.class);
return user;
}
}
这是我在build.xml中添加的
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="dist/lib/aopalliance-repackaged-2.5.0.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/commons-codec-1.11.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/commons-lang-2.6.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/commons-logging-1.1.3.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/hk2-api-2.5.0.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/hk2-locator-2.5.0.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/hk2-utils-2.5.0.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/hsqldb.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/icepdf-core-6.2.2.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/icepdf-viewer-6.2.2.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/itextpdf-5.5.3.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jackcess-2.1.11.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.activation-api-1.2.1.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.annotation-api-1.3.4.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.inject-2.5.0.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.json.bind-api-1.0.1.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.json-1.1.5.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.persistence-api-2.2.2.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.servlet-api-4.0.2.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jakarta.ws.rs-api-2.1.5.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/javafx-ui-common.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/javassist-3.22.0-GA.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-client.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-common.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-container-servlet.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-container-servlet-core.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-hk2.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-media-jaxb.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-media-json-binding.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-media-sse.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jersey-server.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/jpedal_lgpl.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/org.apache.commons.io.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/org.osgi.core-4.2.0.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/osgi-resource-locator-1.0.1.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/yasson-1.0.3.jar" excludes="META-INF/*" />
<zipfileset src="dist/lib/ucanaccess-4.0.4.jar" excludes="META-INF/*" />