java.lang.ClassNotFoundException with Tomcat WAR file



我正试图为一个项目做一个简单的REST API,我目前正在工作,以简化我每天必须做的任务,当我到达我托管它的地方时,我遇到了500服务器错误。查看(tomcat主目录)/logs/localhost.2021-10-22.log的日志,我发现了这个错误:

22-Oct-2021 21:33:58.974 SEVERE [http-nio-13760-exec-64] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet [OrderServlet]
java.lang.ClassNotFoundException: api.OrderServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1407)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1215)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:538)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:519)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:149)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1070)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:788)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:128)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

我也有"不存在":

package api;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
import data.Order;
public class OrderServlet extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

String requestUrl = request.getRequestURI();
String id = requestUrl.substring("cafe/orders/".length());


Order order = Requests.getInstance().getOrder(id);

if (order != null) {
String json = "{n";
json += ""id": " + JSONObject.quote(order.getID()) + ",n";
json += ""id": " + JSONObject.quote(order.getName()) + ",n";
json += ""id": " + JSONObject.quote(String.valueOf(order.getTime())) + ",n";
//various parameters removed to prevent abuse in the future (I'm looking at you, Dax)
//I'd rather not have a coffee order show up with a comically large amount of creamers in it
json += "};";
response.getOutputStream().println(json);
} else {
//order was not found
response.sendError(404);
}
}

@Override
public void doPost(HttpServletRequest request, HttpServletResponse responce) throws IOException, ServletException {
String id = request.getParameter("id");
String name = request.getParameter("name");
int time = Integer.parseInt(request.getParameter("time"));
//various parameters removed

Requests.getInstance().putOrder(new Order(id, name, time, type, //various parameters removed
));
}
}

我检查了类实际上存在,我试过重建类,导入非编译文件和乱搞web.xml,我检查了有没有一个随机的jre6库在构建路径(从这里)。我没有使用Maven, Tomcat能够很好地加载文档和管理器。如何使Tomcat可以识别该类?

看起来文件没有正确地从Eclipse导出,因此需要手动修复这个问题。

编辑:原来问题是我的源文件夹不是Eclipse试图导出的文件夹。进入属性>部署程序集和更改源文件夹修复了它(感谢@Piotr P Karwasz!)

相关内容

  • 没有找到相关文章

最新更新