前些天刚好开始Struts的学习,但是在配置Struts 2的时候就遇到了很大的障碍,我使用的Struts 2版本是2.2.1(即Struts 2.2.1),我参考了《精通J2EE》(第二版)里的有关Struts 2的配置内容,该书使用的是Struts 2.0.9)。我首先从Struts 2.2.1的lib文件下复制了“freemarker-2.3.16.jar,ognl-3.0.jar,struts2-core-2.2.1.jar,xwork-core-2.2.1.jar”,然后粘贴在了项目的lib文件下,也可以通过“Add External JARs”的形式导入,但是如上所作后,在启动Tomcat时出现了如下的错误:
警告: Could not create JarEntryRevision for [jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar]
...
2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger info
信息: Parsing configuration file [struts-default.xml]
2010-9-24 11:16:02 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
严重: Dispatcher initialization failed
Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
<wbr><wbr><wbr></wbr></wbr></wbr>...
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
<wbr><wbr><wbr></wbr></wbr></wbr>...
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
<wbr><wbr><wbr></wbr></wbr></wbr>...
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
<wbr><wbr><wbr></wbr></wbr></wbr>...
Caused by: Unable to load configuration. - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
<wbr><wbr><wbr></wbr></wbr></wbr>...<wbr></wbr>
Caused by: Unable to load bean: type:org.apache.struts2.dispatcher.multipart.MultiPartRequest class:org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file:/E:/Programming/apache-tomcat-6.0.26/webapps/Struts2/WEB-INF/lib/struts2-core-2.2.1.jar!/struts-default.xml:48:178
<wbr><wbr><wbr></wbr></wbr></wbr>...<wbr></wbr>
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
<wbr><wbr><wbr></wbr></wbr></wbr>...
Caused by:java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
<wbr><wbr><wbr></wbr></wbr></wbr>...
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2010-9-24 11:16:02 org.apache.catalina.core.StandardContext start
严重: Context [/Struts2] startup failed due to previous errors
<wbr></wbr>
这些错误很让我摸不着头脑,经多方查阅资料后,在Struts 2.2.x中应该导入如下7个JAR文件
1)<wbr><wbr></wbr></wbr>commons-fileupload-1.2.1.jar
2)<wbr><wbr></wbr></wbr>commons-io-1.3.2.jar
3)<wbr><wbr></wbr></wbr>freemarker-2.3.16.jar
4)<wbr><wbr></wbr></wbr>javassist-3.7.ga.jar
5)<wbr><wbr></wbr></wbr>ognl-3.0.jar
6)<wbr><wbr></wbr></wbr>struts2-core-2.2.1.jar
7)<wbr><wbr></wbr></wbr>xwork-core-2.2.1.jar
8) commons-lang-2.5.jar
- asm-x.x.jar
- asm-commons-x.x.jar
- asm-tree-x.x.jar
- commons-fileupload-X.X.X.jar
- commons-io-X.X.X.jar
- commons-lang-X.X.jar
- freemarker-X.X.X.jar
- javassist-X.X.X.jar
- ognl-X.X.X.jar
- struts2-core-X.X.X.X.jar
- xwork-core-X.X.X.jar
<wbr></wbr>
其实,这里还有一个小窍门,我们可以将Struts 2.2.x根目录下的apps文件夹下的struts2-blank-2.2.1.war文件进行解压,然后找到WEB-INF下的lib目录,我们可以发现里面列出了7个JAR文件,刚好这7个就是我们配置Struts 2.2.x需要导入的JARs文件:
现在服务器应该就可以正常启动了!