The method setXmlVersion(String) is undefined for the type Document
开发时我们可能会碰到这样的问题,它产生的原因是我们实际需要调用的是 JDK 环境 rt.jar 下的 org.w3c.dom.org.w3c.dom.Document ,但事实上 Eclipse 等 IDE 工具此时自动为我们调用的是 J2EE 中的 xerces\xmlParserAPIs\2.6.2\xmlParserAPIs-2.6.2.jar ,这一点通过 Ctrl 左键点击 Document 类可以发现。
发现问题出在哪里就好解决了,我们需要做的是调整 Eclipse 的调用顺序。
项目右键 > Properties > Java Build Path > 右边 Order and Export
把 JRE System Library 通过点击 Up 按钮放到 J2EE(Maven Dependencies) 的上面即可。
End .