[英]While running an applet on the browser gives a run time error :- “java.lang.NoClassDefFoundError: com.sun.jersey.api.client.config.ClientConfig”
I have included all the jar files. 我已经包含了所有的jar文件。 This applet is actually calling a restful web service in the localhost only.When I am just running JarExampleApplet.java as "run-as applet", it is working fine.But when I am running it in Browser it is giving me a run time error "java.lang.NoClassDefFoundError: com.sun.jersey.api.client.config.ClientConfig" 这个applet实际上仅在本地主机中调用一个宁静的Web服务。当我仅以“ run-as applet”身份运行JarExampleApplet.java时,它运行良好。但是,当我在Browser中运行它时,它给了我运行时间错误“ java.lang.NoClassDefFoundError:com.sun.jersey.api.client.config.ClientConfig”
import java.applet.Applet;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import javax.ws.rs.core.MediaType;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.LoggingFilter;
import com.sun.jersey.core.util.Base64;
@SuppressWarnings("serial")
public class JarExampleApplet extends Applet {
public static final String BASE_URI = "http://localhost:8080/RESTfulWS";
public static final String PATH_NAME = "/file/upload_json/";
public void init ()
{
JarExampleApplet my_client = new JarExampleApplet();
File file_upload = new File("C:/Grails.pdf");
try{
my_client.sendFileJSON(file_upload);
}
catch(Exception ex)
{
System.out.println("Exception : " + ex);
}
}
public void paint(Graphics g) {
g.drawString("This Applet was read from a .jar file.", 0, 25);
}
public void sendFileJSON(File file_upload) throws JSONException, IOException{
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.addFilter(new LoggingFilter());
WebResource resource = client.resource(BASE_URI);
WebResource service = resource.path("rest").path(PATH_NAME);
JSONObject data_file = new JSONObject();
data_file.put("file_name", file_upload.getName());
data_file.put("file", convertFileToString(file_upload));
ClientResponse client_response = service.accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, data_file);
System.out.println(" "+client_response);
System.out.println("Status: "+client_response.getStatus());
client.destroy();
}
//Convert my file to a Base64 String
private String convertFileToString(File file) throws IOException{
byte[] bytes = Files.readAllBytes(file.toPath());
return new String(Base64.encode(bytes));
}
}
////////////////////////HTML File /////////////////////// HTML文件
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<applet code="JarExampleApplet.class" archive="JarExampleApplet.jar" height="200" width="400"></applet>
</body>
</html>
May be you are missing the jersey-client.jar
for the same. 可能是因为您缺少jersey-client.jar
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.