从tomcat9迁移到tomcat10,系统仍然尝试加载javax/servlet/http/HttpServlet

问题描述 投票:0回答:1

我的servlet曾经在tomcat9上运行。我尝试使用tomcat10。

我从构建路径中删除了 javax.servlet-api-3.1.0.jar 并添加了 jakarta.servlet-api-5.0.0.jar。

我在代码中更改了对 javax.servlet 的任何引用:

//import javax.servlet.*;
//import javax.servlet.http.*;

import  jakarta.servlet.*;
import  jakarta.servlet.http.*;

到目前为止,我仍在导入 javax.mail 和 javax.crypto,但如果有必要和可能的话,我稍后会更改它。

我使用 ant 构建我的项目,javac 成功在我的 tomcat10 安装的 webapps 文件夹中创建类:

destdir="/var/lib/tomcat10/webapps/${app_version}/WEB-INF/classes"

但是 servlet 不会启动,localhost.2024-06-27.log 文件中包含以下内容:

27-Jun-2024 15:23:00.211 SEVERE [https-openssl-nio-8080-exec-198] org.apache.catalina.core.ApplicationContext.log HTMLManager: Error starting [/tomcat_app]
    org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/tomcat_app]]
        at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:419)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:186)
        at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1312)
        at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:656)
        at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:205)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
        at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:190)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
        at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:129)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:597)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93)
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:673)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
        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.base/java.lang.Thread.run(Thread.java:829)
    Caused by: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1022)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2352)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:800)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1317)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1022)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2352)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:800)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1317)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1022)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2352)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:800)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1317)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
        at java.base/java.lang.Class.getDeclaredFields0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredFields(Class.java:3061)
        at java.base/java.lang.Class.getDeclaredFields(Class.java:2248)
        at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:104)
        at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:270)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:137)
        at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:69)
        at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:333)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:994)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:304)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:114)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4766)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
        ... 33 more
    Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1353)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1165)
        ... 67 more

整个工程漫长而复杂。似乎有一个类仍然尝试加载javax/servlet/http/HttpServlet。

如何找出哪个类,或者更一般地说,我的代码或配置的哪一部分仍在尝试加载 javax/servlet/http/HttpServletload?

编辑:

我发现我的一个类扩展了 com.google.gwt.user.server.rpc.RemoteServiceServlet 类。 com.google.gwt.user.server.rpc.RemoteServiceServlet 类实现了 javax.servlet.Servlet,这可能是一个问题。也许我应该使用 com.google.gwt.user.server.rpc.jakarta.RemoteServiceServlet 代替。我看到它位于 gwt-servlet-jakarta.jar 中。到目前为止,我还没有找到在哪里下载gwt-servlet-jakarta.jar。现在将 GWT 与 Tomcat10 一起使用是否太早了?

java tomcat servlets ant
1个回答
0
投票

我的一个类扩展了实现 javax.servlet.Servlet 的 com.google.gwt.user.server.rpc.RemoteServiceServlet 类。我将扩展名更改为 com.google.gwt.user.server.rpc.jakarta.RemoteServiceServlet,包含在我在此处下载的 jar 文件中:https://repo.vertispan.com/gwt-snapshot/org/gwtproject/gwt- servlet-jakarta/2.11.0-jakarta-SNAPSHOT/

我希望这个自我回答能够帮助其他遇到同样问题的人。

© www.soinside.com 2019 - 2024. All rights reserved.