【现象】
eclipse+jetty启动一个java web工程的时候,报错如下:
2015-09-06 13:29:22.884:WARN::failed struts2: Unable to load configuration. - bean - jar:file:/D:/jars/omch_hubei/struts2-core-2.2.1.jar!/struts-default.xml:71:140
2015-09-06 13:29:22.884:WARN::Failed startup of context org.mortbay.jetty.webapp.WebAppContext@6c8f4c{/omch,D:\SVN\IP_AIOBSJP\src\aiip-apps\aiip-apps-report-hadoop\src\main\webapp}
Unable to load configuration. - bean - jar:file:/D:/jars/.../struts2-core-2.2.1.jar!/struts-default.xml:71:140
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:713)
at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
at org.mortbay.jetty.Server.doStart(Server.java:224)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
at runjettyrun.Bootstrap.main(Bootstrap.java:86)
2015-09-06 13:29:22.907:INFO::Started [email protected]:8080
【原因分析】
工程没有使用maven库,所有jar包都在自己创建的user library下。
使用的是struts-2.2.1,怀疑是引用的jar包不全。
【解决办法】,查看用到了哪些jar包。
查看struts2自带示例程序struts2-blank.war,用rar解压后会看到用到了如下基本的jar包:
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
freemarker-2.3.16.jar
javassist-3.7.ga.jar
ognl-3.0.jar ----------------------------------->>>> 我少的就是这个。添加到自己的user library下,重新编译,就OK啦。
struts2-core-2.2.1.jar
xwork-core-2.2.1.jar
另附struts2-core-2.2.1.jar编译打包用的pom.xml
4.0.0
org.apache.struts
struts2-parent
2.2.1
org.apache.struts
struts2-core
jar
Struts 2 Core
scm:svn:http://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_2_1/core
scm:svn:https://svn.apache.org/repos/asf/struts/struts2/tags/STRUTS_2_2_1/core
http://svn.apache.org/viewcvs.cgi/struts/struts2/tags/STRUTS_2_2_1/core
2.2
3.0
org.apache.myfaces.tobago
maven-apt-plugin
1.0.15
uri=/struts-tags,tlibVersion=${tlib.version},jspVersion=2.0,shortName=s,displayName="Struts Tags",
outFile=${basedir}/target/classes/META-INF/struts-tags.tld,
description="To make it easier to access dynamic data;
the Apache Struts framework includes a library of custom tags.
The tags interact with the framework's validation and internationalization features;
to ensure that input is correct and output is localized.
The Struts Tags can be used with JSP FreeMarker or Velocity.",
outTemplatesDir=${basedir}/src/site/resources/tags
target
false
true
true
true
org.apache.struts.annotations.taglib.apt.TLDAnnotationProcessorFactory
1.5
**/*.java
compile
execute
maven-javadoc-plugin
2.2
${basedir}/src/main/java;${basedir}/../xwork-core/src/main/java
UTF-8
Struts Packages
org.apache.struts2*
XWork Packages
com.opensymphony.xwork2*
private
http://java.sun.com/j2se/1.5.0/docs/api
http://java.sun.com/javaee/5/docs/api/
http://jakarta.apache.org/commons/logging/apidocs/
http://logging.apache.org/log4j/docs/api/
org.codehaus.mojo
rat-maven-plugin
1.0-alpha-2
pom.xml
src/**
src/test/resources/org/apache/struts2/views/jsp/ui/*
src/main/resources/org/apache/struts2/static/domTT.js
src/test/resources/org/apache/struts2/interceptor/validation/*
src/site/resources/tags/**
src/main/resources/*LICENSE.txt
alljars
maven-javadoc-plugin
2.2
attach-source
jar
${basedir}/src/main/java;${basedir}/../xwork-core/src/main/java
UTF-8
Struts Packages
org.apache.struts2*
XWork Packages
com.opensymphony.xwork2*
private
http://java.sun.com/j2se/1.5.0/docs/api
http://java.sun.com/javaee/5/docs/api/
http://jakarta.apache.org/commons/logging/apidocs/
http://logging.apache.org/log4j/docs/api/
org.apache.maven.plugins
maven-source-plugin
attach-source
jar
default-tools.jar
java.vendor
Sun Microsystems Inc.
com.sun
tools
1.5.0
system
${java.home}/../lib/tools.jar
org.apache.struts.xwork
xwork-core
${version}
org.freemarker
freemarker
2.3.16
javax.servlet
servlet-api
2.4
provided
javax.servlet
jsp-api
2.0
provided
ognl
ognl
${ognl.version}
org.apache.velocity
velocity
1.6.3
true
org.apache.velocity
velocity-tools
1.3
true
struts
struts
velocity
velocity
commons-fileupload
commons-fileupload
1.2.1
commons-io
commons-io
1.3.2
org.springframework
spring-test
${struts2.springPlatformVersion}
test
junit
junit
compile
true
3.8.2
org.easymock
easymock
2.4
test
mockobjects
mockobjects-core
0.09
test
mockobjects
mockobjects-jdk1.3
0.09
test
mockobjects
mockobjects-alt-jdk1.3
0.09
test
mockobjects
mockobjects-alt-jdk1.3-j2ee1.3
0.09
test
mockobjects
mockobjects-jdk1.3-j2ee1.3
0.09
test
jmock
jmock
1.0.1
test
log4j
log4j
1.2.9
test
org.apache.struts
struts-annotations
compile
true
org.testng
testng
5.1
compile
true
jdk15
org.springframework
spring
${struts2.springPlatformVersion}
compile
true