我在使用 Struts2 v6.3.0.2 时运行 Web 应用程序时遇到问题。当我尝试在浏览器上加载页面时,收到以下错误。
过滤器 struts2 抛出的未捕获异常:java.lang.NoClassDefFoundError:org.apache.struts2.RequestUtils
请问有人可以帮忙吗?
我使用的工具是 eclipse IDE、Java 8 和作为应用程序服务器的 WebSphere v9。我使用 Maven 来获取所有依赖项。下面是我的 pom.xml。
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>6.3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jgeppert.struts2.bootstrap</groupId>
<artifactId>struts2-bootstrap-plugin</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>6.3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.9</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.clerezza.ext</groupId>
<artifactId>org.json.simple</artifactId>
<version>0.4</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
下面还有我的 web.xml。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>mysite</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
<!-- <url-pattern>results.jsp</url-pattern> -->
</filter-mapping>
</web-app>
当我在 pom.xml 中将 Struts2 版本更改为 2.5.33 并将 Struts2-convention-plugin 更改为 2.5.33 时,它可以工作,并且我可以看到我的 index.jsp 页面。当我使用当前版本的struts2时它不起作用。我尝试了 Maven Clean、Project Clean、重建项目、删除目标文件夹内容、查看 struts2 在构建路径中,并验证了 struts2 包中存在类“org.apache.struts2.RequestUtils”,但我仍然收到错误。请坚持?
您正在使用第三方插件
<dependency>
<groupId>com.jgeppert.struts2.bootstrap</groupId>
<artifactId>struts2-bootstrap-plugin</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>
对于当前版本的 Struts 6.3.0.2 来说可能已经过时了。
您还应该知道,升级依赖项时需要运行 Maven
clean
以从打包中删除旧的依赖项。检查目标的 lib
文件夹以仅保留当前依赖项。