5
java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

I added following jar files:

commons-fileupload-1.2.1.jar
commons-logging-1.1.1.jar
freemarker-2.3.16.jar
ognl-3.0.jar
servlet-api.jar
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar
Roman C
  • 49,761
  • 33
  • 66
  • 176
Hardik Bhalani
  • 863
  • 2
  • 8
  • 24

10 Answers10

2

I work with Struts2/Tomcat6 (in Eclipse) every day and I get this exception from time to time (it comes and goes !!!). What helps make it go away is to reorder the build path order. So, I go to properties of the project (right click on it -> properties), Java Build path move move up the struts-2-core .jar...enter image description here

luigi7up
  • 5,779
  • 2
  • 48
  • 58
2

Copy all required jar files and paste them in WEB-INF/lib folder. Then run your project. I hope it helps.

Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
1

I was having the same exception, and in my case it was an error in the web.xml file.

It was:

<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.
    StrutsPrepareAndExecuteFilter
</filter-class>

As you can see, there is a line-break after filter. and after StrutsPrepareAndExecuteFilter.

I solved the problem just removing them:

<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

If this is your case too, it may solve de problem.

Renato Lochetti
  • 4,558
  • 3
  • 32
  • 49
1

I got the same problem . But I found the solution.

Even struts2 package include all bundle of jar files those are not compatible to each other . Only if following files should be compatible . jar files that i mention are compatible and you can download from Struts site and use it (make sure to remove existing versions before adding to the library)

  • freemarker-2.3.8.jar
  • ognl-2.6.11.jar
  • struts2-core-2.2.1.jar
  • xwork-core-2.2.1.jar
Marko
  • 20,385
  • 13
  • 48
  • 64
0

EDIT: I went through the same problem again. The solution is pretty simple (if you're not committing the mistake below). You have to put the libraries (struts2 in this case) in the WEB-INF/lib folder. To do so, do not directly copy the ".jar"s. Instead, go to : "right click on the project" > Properties > Deployment Assembly > Add.. > Add your libraries' current path. It worked for me when using Maven (I selected the 'Maven Dependencies' folder).


BEFORE EDIT:

I felt kind of obliged to give an answer here.. I had the same trouble and I didn't find the answer on the internet.. and it's pretty simple.. (I called myself stupid many times lol)

I guess you are putting the < filter > and < filter-mapping > struts configurations on the wrong web.xml. It should be your application's xml, not your server's.

At least, that's what happened to me. Since I'm new to java web applications, I didn't know the difference between the documents (web.xml) and forgot an important thing : always download the examples and compare it with my current project.

Breno Inojosa
  • 602
  • 1
  • 10
  • 20
0

Invalid jar file path.Check the jar files on server & set valid path for your jar files.

JDGuide
  • 6,239
  • 12
  • 46
  • 64
0

It was mainly because of compatability issue in struts2-core jar file . if you use this org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter , then you need to use struts2-core 2.3.15 version and above

Pravin
  • 645
  • 3
  • 7
  • 21
0

add all jar related to struts as BUILD PATH also copy same file into WEB-INF/lib

Karan
  • 557
  • 6
  • 17
0

According to findjar you may have to add struts2-core-2.1.6.jar or above

Suraj Chandran
  • 24,433
  • 12
  • 63
  • 94
  • 1
    Didn't he say this jar file was already added? I presume "struts2-core-2.2.1.jar" works just as fine as well. – Tovi7 Apr 12 '11 at 09:59
  • jar file is not the issue...I tried b adding struts2-core-2.1.6.jar file having class defination of org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.class – Hardik Bhalani Apr 12 '11 at 10:03
  • here is my web.xml file with necessary tags is there any problem in that..? struts2 org.apache.struts2.dispatcher.FilterDispatcher struts2 /* home.jsp – Hardik Bhalani Apr 12 '11 at 10:05
0

You said that you'd put the JAR files ...

in web-inf folder and also in build-path>libraries under eclipse dynamic web project

The JAR files need to be in

.../webapps/yourWebapp/WEB-INF/lib

If you put them directly into the WEB-INF directory, the web container won't put them onto the webapp's classpath.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • ya its there itself....generally web-inf/lib folder is under the path that u had mentioned....I put them in that specific folder already – Hardik Bhalani Apr 12 '11 at 10:19
  • Well, I'm stumped. Perhaps you should show us the complete stacktrace. (This might reveal the real cause of the problem.) – Stephen C Apr 12 '11 at 11:06
  • 1
    I must say though, it would be easier to help you if getting you to give us details wasn't so difficult. For instance, if you'd actually said that you'd put the JAR in WEB-INF/lib rather than *"in web-inf folder"*, I wouldn't have wasted everyone's time with this answer ... – Stephen C Apr 12 '11 at 11:09