0

I'm aware that there are plenty of similar questions on StackOverflow, but I guess I went through each of them and tried all the suggested ones, but none of them worked.

I am trying to migrate an application from struts 1 to struts 2, but for makes things easier I'm trying first to migrate the struts1 sample applications in order to get confident with the steps. The sample applications I'm talking about are the ones in the apps folder of this repository.

So, this is my current configuration:

  • maven
  • Java 8
  • Tomcat 9
  • Struts 1.4
  • Struts 2.5

The steps that I've done so far have been:

  1. Add struts2-core and log4j2 dependencies in the pom.xml file, and install them through maven
  2. Change the web.xml file to include struts 2, according to official documentation.
  3. Create a struts.xml file in the classpath, currently that file doesn't contain any action but just the structure.

The above-mentioned files look like this:

web.xml (excerpt):

 <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
 </filter>
 <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
 </filter-mapping>

 <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>*.action</url-pattern>
 </filter-mapping>

struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>
    <constant name="struts.devMode" value="true"/>

    <package name="default" namespace="/" extends="struts-default">

    </package>

    <!-- Add addition packages and configuration here. -->
</struts>

pom.xml (excerpt):

   <dependency>
       <groupId>org.apache.struts</groupId>
       <artifactId>struts2-core</artifactId>
       <version>2.5.22</version>
       <scope>compile</scope>
   </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.12.1</version>
    </dependency>

In the end, the maven dependencies section looks like this:

enter image description here

While the WEB-INF/lib folder in the target folder looks like this:

enter image description here

So I'm sure that all the required dependencies are present in the target. Despite this, I keep getting the error:

org.apache.catalina.core.StandardContext filterStart SEVERE: Exception starting filter [struts2] java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter

I'm sure that the class org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter exists, it's spelled correctly and it's correct for the version of struts2 that I'm using, since if I import the class in a Java file, it gets built succesfully.

I know that the problem is very common and my request can sound stupid, but I've checked literally any question that I found on the web about this problem and none of the solutions worked.

I hope that someone could give me a hint. Thank you

1

1 Answer 1

0

Your pom.xml entry for the Struts 2 lib:

   <dependency>
       <groupId>org.apache.struts</groupId>
       <artifactId>struts2-core</artifactId>
       <version>2.5.22</version>
       <scope>compile</scope>
   </dependency>

If you're running via Maven (which you should) you'll need it beyond compile time.

I would leave dependency management up to Maven and not try to do it manually, even if the WEB-INF/lib image has been truncated (it's missing at least the XWork dependency).

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

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.