今天在更新項(xiàng)目后進(jìn)行編譯時(shí),出現(xiàn)如下錯(cuò)誤一堆:

Google之,在stackoverflow
上看到如下的解決方法:
I came here with the same problem. Even worse: I had two projects side by side, both targetting the same JRE (1.6), and one was able to resolve Node.getTextContent() while the other wasn't. I resolved it sort of by accident; I went to project properties | Java Build Path | Order and Export tab, selected the JRE (which was at the bottom of the list) and clicked the "Top" button to move it to the top. My problem went away. It appears that the Node I wanted was hidden by another one. :-\ Maybe this will help with your problem.
大體解決方法就是:
在項(xiàng)目的Java Build Path | Order and Export
選項(xiàng)卡中,將JRE System Library
選中,并Top
置頂。然后再進(jìn)行編譯即可。如圖:

但是上面并沒(méi)有給出原因。
其實(shí)順著問(wèn)題的解決思路想想,肯定是jar出現(xiàn)了沖突所致。于是我就在項(xiàng)目的jar包中找可能含有org.w3c.dom.Element
這個(gè)類的jar包。既然將JRE的lib進(jìn)行了置頂,那么就有理由猜測(cè)JRE-lib里存在這個(gè)類的相關(guān)方法。
最終,在rt.jar
和xml-apis.jar
和中找到了。應(yīng)該就是這兩個(gè)jar沖突所致,由于引用優(yōu)先級(jí)的不同導(dǎo)致引用了xml-apis.jar
中的方法。
其實(shí)在pom.xml
中并沒(méi)有這個(gè)jar的直接引用,在Dependency Hierarchy
視圖中搜索xml-apis
可以發(fā)現(xiàn),它其實(shí)是由于dom4j
的依賴而引入的。如圖:

解決方法:右擊該jar,選擇exclude maven artifact
,確認(rèn)并保存,重新編譯即可:

最終的pom.xml
中只是在dom4j
的<dependency>
中多了這么一段<exclusions>
:
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<exclusions>
<exclusion>
<artifactId>xml-apis</artifactId>
<groupId>xml-apis</groupId>
</exclusion>
</exclusions>
</dependency>
參考:
http://stackoverflow.com/questions/5534864/compilation-error-in-node-gettextcontent-for-jdk-6
http://www.educity.cn/wenda/364108.html
如果覺(jué)得有用,歡迎關(guān)注我的微信,有問(wèn)題可以直接交流:
