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
3
  • 3
    'Be spesific'. Title should "java.lang.ClassNotFoundException throwing some error" instade of "how to solve this error" Commented Apr 12, 2011 at 9:51
  • Also, you added those jar files where or how? Commented Apr 12, 2011 at 9:54
  • in web-inf folder and also in build-path>libraries under eclipse dynamic web project Commented Apr 12, 2011 at 9:56

10 Answers 10

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

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

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.

Comments

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

Comments

0

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

3 Comments

Didn't he say this jar file was already added? I presume "struts2-core-2.2.1.jar" works just as fine as well.
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
here is my web.xml file with necessary tags is there any problem in that..? <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>home.jsp</welcome-file> </welcome-file-list>
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.

3 Comments

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
Well, I'm stumped. Perhaps you should show us the complete stacktrace. (This might reveal the real cause of the problem.)
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 ...
0

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

Comments

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.

Comments

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

1 Comment

The ng filter has been the recommended filter since 2.1.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.