1

I got this error when starting the app.

SEVERE: Exception starting filter struts2 java.lang.ClassNotFoundException: 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

and the server gave this error twice in a row.

I have struts2-core-2.3.15.2.jar in WEB-INF/lib and imported into build path. I do not understand why StrutsPrepareAndExecuteFilter cannot be found.

The application can get started. thats no problem. the problem is because of this error, struts2 cannot redirect the action.

I use tomcat 7 and struts2 2.3.16. It's Tomcat 7, the servelet-api is not 3.0 I guess. I tried to put servelet-api-3.0 in tomcat/lib but it's not compatible.

What's the problem?

Jars used:

enter image description here

Roman C
  • 49,761
  • 33
  • 66
  • 176
user3560221
  • 51
  • 2
  • 7
  • It's either not being found or you're missing a dependency. You'll need to make sure you're deploying what you think you are. – Dave Newton Apr 22 '14 at 14:03
  • @Roman C, i have more jars. just didnt list all of them here. too many. the problem is only about this jar i think, cuz StrutsPrepareAndExecuteFilter is only from struts2-core-2.3.15.2.jar. – user3560221 Apr 22 '14 at 14:13
  • @DaveNewton , what do u mean? – user3560221 Apr 22 '14 at 14:14
  • yes, more jars, more compilations, build the war file and deploy it to the server, look at the apps package of the struts distro. The minimum jars are in the struts basic demo app... – Roman C Apr 22 '14 at 14:21
  • @RomanC , of course i have more jars. it's not about others. i dont use maven. – user3560221 Apr 22 '14 at 14:31
  • @user3560221 You should, or something similar; managing transitive dependencies by hand is a bad idea. – Dave Newton Apr 23 '14 at 12:36

4 Answers4

1

The following minimum jars should be on your classpath:

  • asm-3.3.jar
  • asm-commons-3.3.jar
  • asm-tree-3.3.jar
  • commons-fileupload-1.3.jar
  • commons-io-2.2.jar
  • commons-lang3-3.1.jar
  • commons-logging-1.1.3.jar
  • freemarker-2.3.19.jar
  • javassist-3.11.0.GA.jar
  • log4j-1.2.17.jar
  • ognl-3.0.6.jar
  • struts2-core-2.3.16.jar
  • xwork-core-2.3.16.jar

You can also follow How To Create A Struts 2 Web Application.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • i have all of them. this is not my first struts2 project. it was working fine until today. i just replaced all the jars with the ones from struts-2.3.16.1 package. it is still the same. – user3560221 Apr 22 '14 at 15:02
  • See also [this](http://stackoverflow.com/q/5256939/573032) question. – Roman C Apr 22 '14 at 15:06
  • @user3560221 are you sure you have _replaced_ all of them? and you don't have fileupload jar in your class path. Netbeans provide a _clean and build_ feature. there must be something similar in eclipse too. try if it works after that. – maxx777 Apr 22 '14 at 15:39
  • i dont need the features from fileupload jar. and i didnt use it either before. it was no problem... – user3560221 Apr 22 '14 at 15:41
  • i'm not sure it should be included or not but all the tutorials says that this jar should be included. further the default interceptor stack uses file upload interceptor. – maxx777 Apr 22 '14 at 15:44
  • @RomanC can you throw some light here?? ^ – maxx777 Apr 22 '14 at 15:45
  • @maxx777 ok, i included the fileupload jar. but its still the same.. – user3560221 Apr 22 '14 at 15:56
  • @user3560221 have you re-bulit your project? – maxx777 Apr 22 '14 at 16:00
  • @maxx777 what do u mean re-build? i cleaned the server and project and deployed again. the application can get started. thats no problem. the problem is because of this error, struts2 cannot redirect the action. – user3560221 Apr 22 '14 at 16:09
  • i don't get it. whats the exact problem? your question says that dispatcher is not found. you have mention that you are using struts 2.3.15.2 but the image you posted shows 2.3.16.1. don't say u have both of them in your classpath. – maxx777 Apr 22 '14 at 16:15
  • @maxx777 commons-fileupload is the default implementation used for file uploading when maultipart requests are precessed. – Roman C Apr 22 '14 at 16:17
  • i use tomcat 7 and struts2 2.3.16. cuz it's tomcat 7, the servelet-api is not 3.0 i guess. i tried to put servelet-api-3.0 in tomcat/lib. but it's not compatible. – user3560221 Apr 22 '14 at 16:18
  • @ maxx777 of course not both. i just replaced the jars with the latest ones in struts2 2.3.16. but nothing better – user3560221 Apr 22 '14 at 16:20
  • @user3560221 you should check which servlet and jsp apis your server support and use those versions, struts require servlet 2.4 but tomcat 7 supports servlet 3.0 (at least my version 7.0.35) – Roman C Apr 22 '14 at 16:24
  • @Roman C , i doubt that. i am using the original servlet-api downloaded with tomcat 7.0.52. i also tried replacing the servlet-api in my tomcat 7 with servlet-api-3.0, but the application even could not get started.. – user3560221 Apr 22 '14 at 16:29
  • @Roman C , hwo to check which servlet and jsp apis the server supports and uses those versions? – user3560221 Apr 22 '14 at 16:31
  • 1
    Now, I see looking to the picture of your lib folder that you have `commons-lang3-3.3.2.jar` and `commons-io.jar` unknown version. This is a problem, struts 2.3.15.2 doesn't support these jars. To know the version look inside the jar file `manifest.mf` or `pom.xml`. – Roman C Apr 22 '14 at 16:37
  • it was working well last week... – user3560221 Apr 22 '14 at 16:47
  • Do you understand the meaning of the words "work" and "support"? It might work but if you updated some jars it became not working. Use the correct jars and correct versions that is *supported* by the struts2 correct release. – Roman C Apr 22 '14 at 16:51
  • 1
    it has nothing to do with commons-lang3-3.3.2.jar and commons-io.jar. no change. – user3560221 Apr 22 '14 at 20:25
0

the runtime problem was solved eventually by replacing the json jars package.. i think its the versions problems. it is a whole package. i dont remember the link now..

so it seems its better get the jar files from one source but not pick different version.. and these 6 jars should be included together. of course, be careful with the versions. i dont know mine. but it works.

commons-lang.jar
commons-logging.jar
commons-beanutils.jar
commons-collections.jar
json-lib-2.2.2-jdk15.jar
ezmorph.jar

BUT this problem is still there... I have this error, but the app can run

java.lang.ClassNotFoundException: 
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
user3560221
  • 51
  • 2
  • 7
0

If you use Intellij IDEA, the reason maybe you did not add struts-xxx.xxx.jar file to artifacts.To solve this problem you just need open Project structure >> problems >> add struts x.x.x to artifacts(righit click on the problem option)

It works for me ,may it helps you.

-1

If you are using external JRE, it may not work. Instead use the internal JRE (which is inside JDK)

In the project

Go to Build path

-->Configure Build path

-->Libraries

-->Add Libraries

-->Installed JRRs

--> Give path of "JDK"(and not external JRE)

-->Finish.

Refresh the project and it would work.

Parth Pithadia
  • 276
  • 1
  • 3
  • 18