gpt4 book ai didi

java - 在 Tomcat 上实现 Jersey 时出现 "javax.servlet.ServletException: java.lang.NoClassDefFoundError"

转载 作者:行者123 更新时间:2023-11-28 23:38:32 25 4
gpt4 key购买 nike

当我尝试使用(“sudo service tomcat7 start”)在 Linux 服务器上的 Tomcat 上实现以下方法时,除此方法外,所有其他方法都可以正常工作。

@GET
@Path("getapk")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getApk() {
System.out.println("GetApk!");
final File apkFile = new File(apkFileLocation).listFiles()[0];
return Response.ok(
new StreamingOutput() {
public void write(OutputStream output) throws IOException,
WebApplicationException {
output.write(Files.readAllBytes(apkFile.toPath()));
}
}
).header("Content-Disposition", ContentDisposition.type("attachment").fileName(apkFile.getName()).build())
.build();
}

奇怪的是,当我在 Eclipse 中“在服务器上运行”时,此方法工作正常。

以下是我收到的错误信息:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NoClassDefFoundError: robertlee/resource/EcgCloudDatabase$1 com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:420) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) root cause

java.lang.NoClassDefFoundError: robertlee/resource/EcgCloudDatabase$1 robertlee.resource.EcgCloudDatabase.getApk(EcgCloudDatabase.java:691) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381) com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) root cause

java.lang.ClassNotFoundException: robertlee.resource.EcgCloudDatabase$1 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1701) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1546) robertlee.resource.EcgCloudDatabase.getApk(EcgCloudDatabase.java:691) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606) com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1511) com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391) com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381) com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538) com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.26 logs.

Apache Tomcat/7.0.26

求助,万分感谢....

最佳答案

您需要在 WEB-INF/lib 中包含包含类 robertlee/resource/EcgCloudDatabase 的 jar 并重新创建您的部署。

关于java - 在 Tomcat 上实现 Jersey 时出现 "javax.servlet.ServletException: java.lang.NoClassDefFoundError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22366213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com