今天学习DWR,根据官方网上的资料,直接下载了dwr.war进行测试,但是报下面的错误:
javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
javax.xml.transform.TransformerFactory.newInstance(Unknown Source)
uk.ltd.getahead.dwr.convert.DOMConverter.<init>(DOMConverter.java:157)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
java.lang.reflect.Constructor.newInstance(Constructor.java:494)
java.lang.Class.newInstance0(Class.java:350)
java.lang.Class.newInstance(Class.java:303)
uk.ltd.getahead.dwr.impl.DefaultConverterManager.addConverterType(DefaultConverterManager.java:54)
uk.ltd.getahead.dwr.impl.DefaultConfiguration.loadConverter(DefaultConfiguration.java:165)
uk.ltd.getahead.dwr.impl.DefaultConfiguration.loadInits(DefaultConfiguration.java:119)
uk.ltd.getahead.dwr.impl.DefaultConfiguration.addConfig(DefaultConfiguration.java:86)
uk.ltd.getahead.dwr.impl.DefaultConfiguration.addConfig(DefaultConfiguration.java:66)
uk.ltd.getahead.dwr.AbstractDWRServlet.init(AbstractDWRServlet.java:110)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:595)
马上去官方网站(http://getahead.ltd.uk/dwr/getstarted)找答案:官方网站给出的是
What if it doesn't work?The most common error is an XML parser error. It has nothing to do with DWR, and is due to your installation of Tomcat having Xerces installed when it shouldn't or not installed when it should.
JDK 1.3 didn't come with an XML parser, so you will need xercesImpl.jar and xml-apis.jar for that case. JDK 1.4.0 and JDK 1.4.1 did come with an XML parser but it was buggy so you may need to override the default by putting xercesImpl.jar into the tomcat\common\endorsed directory. JDK 1.4.2 and JDK 5 come with a fully working XML parser and you shouldn't need one at all.
按照他们的说法,JDK 1.4.2 and JDK 5根本就不要改什么东西就可以的呀?但为了保险起见,还是将tomcat\common\endorsed下的xercesImpl.jar 和xml-apis.jar换成了最新版的。
再次启动,还是报一样错误。没办法。仔细分析一下错误信息,有这么一句话:
Provider org.apache.xalan.processor.TransformerFactoryImpl not found
也就是这个类所在包找不到,经过一番努力,终于知道org.apache.xalan.processor.TransformerFactoryImpl 是在xnlan.jar里面。于是将xalan.jar拷贝到webapps\dwr\WEB-INF\lib下。
重新启动tomcat
终于搞定!