首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

Eclipse 打開源碼顯示 .class 文件:配置源碼附件解決

     編輯:程式設計綜合問答

Eclipse 中打開庫類(如 JDK、第三方 JAR)時顯示反編譯的 .class 文件而非 .java 源碼,原因是未配置 Source Attachment。本文說明配置方法。

現象

編輯器顯示:

// Class file editor - Source not found
// The source attachment does not contain the source for the file...
// You can change the source attachment by clicking Change Attached Source below.

解決步驟

  1. 下載對應版本的源碼包(如 jdk-8uxxx-src.zip、spring-framework-5.x.x-sources.jar)
  2. 在 Eclipse 中:Package Explorer → 右鍵 JAR → Properties → Java Source Attachment
  3. 選中 External location → External File... 選擇源碼包(.zip/.jar/.目錄均可)
  4. 確定後重新打開類文件即可看到源碼

常見源碼獲取來源

  • JDK:Oracle 官網下載頁面有獨立 src.zip
  • Maven 依賴:右鍵項目 → Maven → Download Sources
  • 第三方庫:官網 Release 頁面通常提供 -sources 包

參考教程

Eclipse 配置 JAR 源碼附件圖文詳解

配置好源碼附件,除方便閱讀實現外,還能在調試時斷點進入庫代碼,大幅提升開發效率。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved