查找從何處加載 java 類 - Find where java class is loaded from

問題:

Does anyone know how to programmaticly find out where the java classloader actually loads the class from?有誰知道如何以編程方式找出 java 類加載器實際從何處加載類?

I often work on large projects where the classpath gets very long and manual searching is not really an option.我經常在類路徑很長並且手動搜索不是真正的選擇的大型項目中工作。 I recently had a problem where the classloader was loading an incorrect version of a class because it was on the classpath in two different places.我最近遇到了一個問題,類加載器加載了一個不正確的類版本,因爲它位於兩個不同位置的類路徑上。

So how can I get the classloader to tell me where on disk the actual class file is coming from?那麼我怎樣才能讓類加載器告訴我實際的類文件來自磁盤上的哪個位置呢?

Edit: What about if the classloader actually fails to load the class due to a version mismatch (or something else), is there anyway we could find out what file its trying to read before it reads it?編輯:如果類加載器由於版本不匹配(或其他原因)而實際上無法加載類,那麼我們是否可以在它讀取之前找出它試圖讀取的文件?


解決方案:

參考一: https://en.stackoom.com/question/xB8
參考二: https://stackoom.com/question/xB8
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章