【问题标题】:Exception starting filter struts2 java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher异常启动过滤器 struts2 java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.FilterDispatcher
【发布时间】:2012-03-08 18:50:18
【问题描述】:

我一直在使用 Eclipse 作为我的 IDE 来开发带有休眠功能的 ORM。我使用 Maven 作为我的构建系统。在学习 Struts 之后,我试图让一个 hello world 正常工作。但是,我不确定是什么问题,它一直给我:

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

文件夹结构如下:

Pom.xml:Pastebin here

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
  <display-name>wah</display-name>

   <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>index.html</welcome-file>
    </welcome-file-list>

</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />

    <package name="default" namespace="/" extends="struts-default">
        <action name="Menu">
            <result>/menu.jsp</result>
        </action>
    </package>  

</struts>

Menu.jsp 有一个简单的 hello world 文本。

谁能帮我解释一下为什么我会收到 ClassNotFoundException 错误。我该如何解决?设置 struts 2 项目的推荐目录结构是什么?

编辑:

以 .zip 格式导出的源代码here

谢谢

【问题讨论】:

  • 按 Ctrl-T 并输入 FilterDispatcher。有结果吗?
  • 你的类路径中有struts2-core jar 文件吗?
  • @UmeshAwasthi 我使用 maven 将 struts2-core 作为依赖项添加到 pom.xml 中。请参阅 pastebin 链接上的最后一个条目。
  • 它显示了什么?上课地点在哪里?
  • @m0skit0 org.apache.struts2.dispatcher

标签: java hibernate jakarta-ee maven struts2


【解决方案1】:

这是我的应用程序文件夹结构,工作正常请参阅

这是 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.tek</groupId>
    <artifactId>marf</artifactId>
    <version>0.0</version>
    <packaging>war</packaging>

    <name>Struts 2 Blank Webapp</name>

    <properties>
        <struts2.version>2.3.1.2</struts2.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.3.1.2</version>
            <exclusions>
                    <exclusion>
                        <artifactId>tools</artifactId>
                        <groupId>com.sun</groupId>
                    </exclusion>
                </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-config-browser-plugin</artifactId>
            <version>2.3.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>2.3.1.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-mock</artifactId>
            <version>2.0.8</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>2.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.21</version> -->
                <groupId>org.apache.maven.plugins</groupId> 
                <artifactId>maven-compiler-plugin</artifactId> 
                <version>2.0.2</version> 

                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <scanTargets>
                        <scanTarget>src/main/webapp/WEB-INF</scanTarget>
                        <scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
                        <scanTarget>src/main/resources/struts.xml</scanTarget>
                        <scanTarget>src/main/resources/example.xml</scanTarget>

                    </scanTargets>
                     <source>1.6</source> 
                    <target>1.6</target> 
                    <compilerArgument>-Xlint</compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这是 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="struts_blank" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <display-name>Struts Blank</display-name>

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

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

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

来源here

【讨论】:

  • 哦,我在文件夹结构中添加 pom.xml 时出错了,但它存在于 marf 的主应用程序中。
  • pom.xml 中的 scanTarget 标签是什么?
  • 是可选的 除了插件自动扫描的文件和目录之外,还要定期扫描的文件和目录列表
  • 你能看一下我上传的源代码吗?在编辑中附加了一个链接。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-13
  • 1970-01-01
  • 2013-04-06
  • 2016-05-13
  • 1970-01-01
相关资源
最近更新 更多