2012-01-02 29 views
0

什麼是寫代碼做如下正確的方法:的Grails/Groovy中 - 確定源.jar文件的類

Base64 base64 = new Base64 
base64.getClass().getSourcePackageAndVersion() // ??? 

我想在我目前Grails項目檢測,如果我從 獲得Base64 commons-codec-1.3.jar或commons-codec-1.4.jar。有沒有辦法強制它在debug/dev模式下使用1.4版本?

回答

0

您可以找到類是從這個加載的jar文件或者classes目錄:

base64.getClass().protectionDomain.codeSource.location 

或既然你已經有了類:

Base64.protectionDomain.codeSource.location 
1

我覺得你的問題是通過通過依賴印製報告的依賴關係樹爲您的開發/調試版本最好的解決(只需更換你的運行ENV):

grails dependency-report runtime 

您可以使用這些信息來迫使你的環境使用正確版本的Base64類。

+0

我的Grails不明白dependency-舉報 – BuddyJoe 2012-01-02 18:51:44

+0

您正在使用哪個grails版本?它應該在1.x和2.x中可用:http://grails.org/doc/2.0.x/ref/Command%20Line/dependency-report.html – 2012-01-02 18:54:35

+0

對不起,當我第一次嘗試運行。現在,當我使用術語'dev'作爲我的環境時,我收到與常春藤相關的錯誤 – BuddyJoe 2012-01-02 18:58:50