英文:
ClassNotFoundException: HttpServletRequest with Struts2 in Eclipse
问题
我有一个项目的两个版本(GIT),较旧的版本(正常工作),和新提交的版本(不工作 - 下面是问题)。
这里是我在Eclipse中遇到的错误:
août 18, 2020 4:22:24 PM org.apache.catalina.core.StandardContext filterStart
GRAVE: Exception au démarrage du filtre struts2
java.lang.NoClassDefFoundError: HttpServletRequest
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.getActionAnnotations(PackageBasedActionConfigBuilder.java:877)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:689)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:355)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:274)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4583)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: HttpServletRequest
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
... 27 more
GRAVE: Exception au démarrage du filtre struts2
可以翻译为 SEVERE: Exception in start of struts2 filter
我看到了这个回答 java.lang.ClassNotFoundException: HttpServletRequest,但是我已经在 WEB-INF/lib
文件夹中没有 servlet-api
,而是在 Tomcat/lib
中有。并且我在当前修改后的项目和旧项目之间有完全相同的 .jar
。
我该怎么办?
英文:
I have 2 versions of a project (GIT), the oldest (work perfectly) and the new one commited (don't work - issue below).
Here the error I have in Eclipse :
août 18, 2020 4:22:24 PM org.apache.catalina.core.StandardContext filterStart
GRAVE: Exception au démarrage du filtre struts2
java.lang.NoClassDefFoundError: HttpServletRequest
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.privateGetPublicMethods(Unknown Source)
at java.lang.Class.getMethods(Unknown Source)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.getActionAnnotations(PackageBasedActionConfigBuilder.java:877)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:689)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:355)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:274)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:967)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:435)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:479)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4583)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: HttpServletRequest
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167)
... 27 more
The GRAVE: Exception au démarrage du filtre struts2
can be translated in SEVERE: Exception in start of struts2 filter
I saw this answer java.lang.ClassNotFoundException: HttpServletRequest but I have already not servlet-api in the WEB-INF/lib
folder but in the Tomcat/lib
. And I have exactly the same .jar
between the current modified project and the old one.
What can I do about this ?
答案1
得分: 1
错误来自于约定插件。这个插件用于按照约定创建附加的配置对象。如果您大量使用注解为Struts操作定义基于Java的配置,那么它会调用反射机制来处理创建运行时配置元素。
NoClassDefFoundError
表明您在当前类加载器的类路径上缺少一些类。通常通过将缺失的 JAR 包添加到类路径中来修复。
如果您的应用程序使用的类加载器与 servlet 容器使用的类加载器不同,则可以忽略此错误。Tomcat 是一个使用多个类加载器的 servlet 容器,位于多线程池中。它也可能存在错误,正如在 8.x 版本中发现的那个。
在许多情况下,在损坏的 servlet 环境中缺少类会导致更改/更新 servlet 容器本身,并从Maven中央仓库下载正确的依赖项。
英文:
The error comes from the convention plugin. This plugin is used to create additional configuration objects by convention. If you havily use annotations to define Java based configuration for struts actions then it invokes a reflection mechanism to process creating runtime configuration elements.
The NoClassDefFoundError
says that you missing some classes on the classpath of the current classloader. Usually it fixed by adding missing jar to the classpath.
It could be ignored if your application used different classloader than a servlet container is used. Tomcat is a servlet container which is using multiple classloaders in the multithreaded pool. It could also have bugs the one had discovered in the 8.x version.
In many ways missing classes in the broken servlet environment leads to change/update the servlet container itself and download correct dependencies from the Maven central repository.
答案2
得分: 0
我终于找到了一个解决方案,但我犹豫是否要发布,因为我不知道自己是如何做到的。
我尝试了以下步骤:
将现有的Eclipse服务器复制到另一个文件夹中。
在Eclipse的服务器视图中创建一个新的服务器,使用新文件夹。
右键单击新服务器 -> 清理并清理Tomcat工作目录...
转到运行 -> 运行配置
完全随机的操作:
双击其中一个服务器
服务器实例开始运行。停止它。重新启动你的项目。问题已消失。
我认为执行了一次清理发布就解决了问题,但我们永远不会知道确切原因...
英文:
I finally found a solution but I hesitated to post because I don't know how I did that.
I was trying this :
Duplicate the existing Eclipse server into another folder.
Create a new server in the Servers view in Eclipse with the new folder.
Click-right on the new server -> Clean and Clean Tomcat Work Directory...
Go to Run -> Run configurations
Totally random action :
Double click on one of the server
The server instance start. Stop it. Restart your project. The problem has disappeared.
I think a clean publish is what I needed but we will never know..
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论