天天看點

CXF的LinkageError錯誤解決

這個問題估計老生常談了。試着跟些一段簡單的代碼程式,很簡單的那種哦~HelloWorld,用CXF實作

三個java檔案《MainServer》、《HelloWorld》、《HelloWorldImpl》代碼就不貼了,很簡單的那種

但是在運作MainServer時報錯了!

資訊: Creating Service {http://test/}HelloWorldImplService from class test.HelloWorld

Exception in thread "main" java.lang.LinkageError: JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/C:/Java/apache-cxf-2.4.1/lib/jaxb-impl-2.2.1.1.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.2 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.6.0/docs/guide/standards/)

。。。

at test.MainServer.main(MainServer.java:17)

我起初是以為程式的錯誤,後來排除該可能。

在網上把錯誤提示“Exception in thread "main" java.lang.LinkageError: JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI ”複制粘貼,谷歌一下(順帶提一句,查技術資料,谷歌很強大,比度娘強多了~),發現有好多的解決方案,而且大都類似

基本上就是由于jdk1.6與CXF的沖突之說,解決方案大同:

在jdK目錄下的jre/lib/中建立endorsed檔案夾,然後将

jaxb-api-2.2.1.jar包

與jaxb-impl-2.2.1.1.jar包

拷入endorsed檔案夾中,并将%JDK_HOME%\jre\lib\endorsed加入classpath後解決

關鍵還是要找準包!我剛開始找得包很多但都不對,一定死2.2.1這樣精确的找才行哦~

經過不停的股溝搜尋,終于找到一個還算是不錯的下載下傳包的地方,特此分享:http://grepcode.com/   進去搜搜就找得到了。

後來哎上述做得,解決成功!

繼續閱讀