1

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 ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
mtnp
  • 314
  • 7
  • 24
  • How are you running this? If it's within a servlet container like Tomcat, you shouldn't have a separate copy of the APIs in the project. – nitind Aug 18 '20 at 15:42
  • I created a simple project without maven and add my libs through the build path. Then, I run my webapp in Tomcat – mtnp Aug 18 '20 at 15:50
  • Another info: sometimes it's HttpServletRequest class which is missing and sometimes it's ServletException class. I don't know why (ClassNotFoundException) – mtnp Aug 18 '20 at 17:42
  • Doing some upgrades? Don't worry. Look at [this](https://stackoverflow.com/a/46729041/573032) answer which should help you to change a version. – Roman C Aug 18 '20 at 20:46
  • Nope, I did not any upgrades. i tried to remove all non necessary libraries in the build path but it's not working neither. – mtnp Aug 19 '20 at 08:13
  • If i remove all Tomcat libraries dependency in the build path I have HttpServletRequest missing. If I add again these libraries (servlet-api.jar included) I have ServletException missing. By the way, I forgot a thing : if I add all libraries to my project I have this ClassNotFoundException hit but the application is started normally on server and I can use it without problems. It's just ignored – mtnp Aug 19 '20 at 08:42

2 Answers2

1

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • I was trying each hint you have suggested me but I think it's rather a Tomcat server problem in your 3rd paragraph. Because, I created a new blank web dynamic project in the same workspace and it runs in the Eclipse console in the same manner than my initial projects, with the same error (and as it's a blank project it cannot be struts2). So I think Eclipse use the only available server and this server use struts classloader I don't know why. I find a solution to force Tomcat to use the project classloader and not the same for all. – mtnp Aug 26 '20 at 14:07
  • 1
    Not sure how and where you have used Eclipse and how it's integrated with Tomcat. If you have a broken environment you cannot run any project on it. You may try any project war to deploy to the production server and it won't work because you have many many problems with packages, frameworks, libraries, internet, and I really don't mind what else it could be. I have suggested you q solution to the problem specific to Tomcat but I was fixed in the newer versions. I recommend you to use different app servers to run and deploy separately. Diagnosing a concrete problem required much more informati – Roman C Aug 26 '20 at 18:07
  • Yes, I think it was a configuration file corrupted on this specific tomcat server but as my project working now resources, packages and things may not be corrupted. It's hard to give more informations cause of confidentiality but the customer don't want to change anything on their environment and I need to adapt myself. So, I was afraid to publish clean the server and loose configuration parameters but it seems working. I hope they will upgrade tomcat server version soon anyway. – mtnp Aug 27 '20 at 08:44
  • We can't know the configuration of your application server, and questions concerned with it offtopic on this site. Because you have posted a question and said that your code is not working, but it is working on another server which is properly administered. You afraid of doing anything because you have not created a testing environment, nither you proposed it to the customer. The customer won't do anything until you give them tests. Here we are helping to solve problems with coding, not to configure and administer application servers. In the docs is outlined all questions related to servers. – Roman C Aug 27 '20 at 17:43
0

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..

mtnp
  • 314
  • 7
  • 24