編寫 Hibernate 映射檔(*.hbm.xml)與配置檔時,若無 DTD 定義,Eclipse 無法提供標籤自動完成與驗證,開發效率大幅降低。本文詳述將 Hibernate DTD 註冊至 Eclipse XML Catalog 的完整步驟。
hibernate.jar(或 hibernate-core-x.x.x.jar)org/hibernate 目錄下找到兩個關鍵檔案:
hibernate-configuration-3.0.dtd(配置檔 DTD)hibernate-mapping-3.0.dtd(映射檔 DTD)選單路徑:Window → Preferences → Web and XML → XML Catalog
點擊右側 Add XML Catalog Entry,依序填入:
| 欄位 | hibernate-configuration-3.0.dtd | hibernate-mapping-3.0.dtd |
|---|---|---|
| Location | 選擇本地解壓出的 hibernate-configuration-3.0.dtd 檔案 |
選擇本地解壓出的 hibernate-mapping-3.0.dtd 檔案 |
| Key Type | URL | |
| Key | https://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd |
https://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd |
.hbm.xml 或 hibernate.cfg.xml<hibernate-mapping 或 <hibernate-configuration 時,應出現屬性自動提示XML Catalog 將遠端 DTD URI 映射至本地檔案,避免每次編輯都下載 DTD,同時啟用 Eclipse 的 XML 編輯器驗證與內容輔助功能。Key 必須與 XML 檔案中 <!DOCTYPE ... SYSTEM "..."> 或 PUBLIC "... 宣告的 URI 完全一致。