前一陣子在開發一個Struts2的原型SCM項目, 用Struts 2+Hibernate開發. 再次遇到了 Struts 2+JDK 6的沖突問題.
出錯信息: Illegal access: this web application instance has been stopped already. Could not load org.xml.sax.SAXException. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java:1244)
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java:1204)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder (Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.<init> (SAX2DOM.java:69)
at com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputH andlerFactory.getSerializationHandler (TransletOutputHandlerFactory.java:187)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutput Handler(TransformerImpl.java:392)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerHandlerImpl.se tResult(TransformerHandlerImpl.java:137)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.setup (DomHelper.java:213)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init> (DomHelper.java:198)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init> (DomHelper.java:189)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init> (DomHelper.java:175)
at com.opensymphony.xwork2.util.DomHelper.parse (DomHelper.java:115)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.load ConfigurationFiles(XmlConfigurationProvider.java:830)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.load Documents(XmlConfigurationProvider.java:131)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init (XmlConfigurationProvider.java:100)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload (DefaultConfiguration.java:130)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration (ConfigurationManager.java:52)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration (Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init (Dispatcher.java:452)
at org.apache.struts2.dispatcher.FilterDispatcher.init (FilterDispatcher.java:201)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter (ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef (ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init> (ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart (StandardContext.java:3696)
at org.apache.catalina.core.StandardContext.start (StandardContext.java:4343)
at org.apache.catalina.core.StandardContext.reload (StandardContext.java:3086)
at org.apache.catalina.manager.ManagerServlet.reload (ManagerServlet.java:912)
at org.apache.catalina.manager.HTMLManagerServlet.reload (HTMLManagerServlet.java:523)
at org.apache.catalina.manager.HTMLManagerServlet.doGet (HTMLManagerServlet.java:113)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11AprProcessor.process (Http11AprProcessor.java:852)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.pro cess(Http11AprProtocol.java:584)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run (AprEndpoint.java:1508)
at java.lang.Thread.run(Thread.java:619)
2008-9-19 0:08:34 org.apache.catalina.core.StandardContext filterStart
嚴重: Exception starting filter struts2
Caught exception while loading file struts-default.xml - [unknown location]
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.load ConfigurationFiles(XmlConfigurationProvider.java:839)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.load Documents(XmlConfigurationProvider.java:131)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.init (XmlConfigurationProvider.java:100)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reload (DefaultConfiguration.java:130)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration (ConfigurationManager.java:52)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration (Dispatcher.java:395)
at org.apache.struts2.dispatcher.Dispatcher.init (Dispatcher.java:452)
at org.apache.struts2.dispatcher.FilterDispatcher.init (FilterDispatcher.java:201)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter (ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef (ApplicationFilterConfig.java:397)
at org.apache.catalina.core.ApplicationFilterConfig.<init> (ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart (StandardContext.java:3696)
at org.apache.catalina.core.StandardContext.start (StandardContext.java:4343)
at org.apache.catalina.core.StandardContext.reload (StandardContext.java:3086)
at org.apache.catalina.manager.ManagerServlet.reload (ManagerServlet.java:912)
at org.apache.catalina.manager.HTMLManagerServlet.reload (HTMLManagerServlet.java:523)
at org.apache.catalina.manager.HTMLManagerServlet.doGet (HTMLManagerServlet.java:113)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke (AuthenticatorBase.java:525)
at org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11AprProcessor.process (Http11AprProcessor.java:852)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.pro cess(Http11AprProtocol.java:584)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run (AprEndpoint.java:1508)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.XML11Configuration cannot be cast to org.apache.xerces.xni.parser.XMLParserConfiguration
at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
at org.apache.xerces.parsers.DOMParser.<init>(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.newDocumentBuilder (Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.SAX2DOM.<init> (SAX2DOM.java:69)
at com.sun.org.apache.xalan.internal.xsltc.runtime.output.TransletOutputH andlerFactory.getSerializationHandler (TransletOutputHandlerFactory.java:187)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutput Handler(TransformerImpl.java:392)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerHandlerImpl.se tResult(TransformerHandlerImpl.java:137)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.setup (DomHelper.java:213)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init> (DomHelper.java:198)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init> (DomHelper.java:189)
at com.opensymphony.xwork2.util.DomHelper$DOMBuilder.<init> (DomHelper.java:175)
at com.opensymphony.xwork2.util.DomHelper.parse (DomHelper.java:115)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.load ConfigurationFiles(XmlConfigurationProvider.java:830)
... 31 more
2008-9-19 0:08:34 org.apache.catalina.core.StandardContext start
現象: 第一次能運行, reload就不行. 啟動不行.
解決思路: 排除法.
先試了Struts2自帶的blank包, 沒問題.
那基本可斷定是其他jar包有沖突, 應該是XML解析包有沖突.
檢查發布後的WEB-INF/lib有兩個XML解析包: xml-apis.jar和xerces- 2.6.2.jar
這種錯誤真正原因不是JDK 6和Struts 2沖突, 而是 MyEclipse Hibernate 類庫中多了兩個包: xml-apis.jar和xerces-2.6.2.jar, 這兩個包的功能和JDK 的沖突了. 解決辦法: 1. 刪除發布後目錄的 WEB-INF/lib/ 下的這兩個文件; 2. 或者使用JDK 1.5來啟動Tomcat 6.
方案1的詳細操作步驟:
a. 先把MyEclipse Hibernate 3.2 Core Lib從BuildPath去掉;
b. 不要重新發布應用, 從發布後的目錄復制全部的jar文件到開發工具下項 目的WEB-INF\lib目錄下, 不要復制其中的xml-apis.jar和xerces- 2.6.2.jar.
c. 停止Tomcat, 重新發布應用或者刪除發布後的目錄下的WEB-INF\lib下的 xml-apis.jar和xerces-2.6.2.jar.
小提示: MyEclipse 自帶類庫有很多問題, 建議讀者自行下載官方網站jar包 進行開發, 比較保險.