cmpcustomer 範例)確認 Application Server 已在 NetBeans「伺服器管理器」註冊並啟動(預設管理員密碼 adminadmin)。
src、各模組獨立目錄)。File → New Project (Ctrl+Shift+N) → Enterprise → Enterprise Application with Existing Sources。src、cmpcustomer-ejb、cmpcustomer-war 的頂層目錄(如 cmpcustomer)。專案名稱自定,專案資料夾不可與來源目錄相同。web-uri 可能不符實際 WAR 檔名。展開專案 Configuration Files,編輯 sun-application.xml,將 web-uri 改為 cmpcustomer-war.war。cmpcustomer-war 專案 → Properties → Libraries → Add Project → 選擇 cmpcustomer-ejb 專案資料夾(非來源目錄),將 EJB 介面類加入 Web 模組類路徑。cmpcustomer-ejb → New → File/Folder → Sun Resources → JDBC Connection Pool,名稱 cmpcustomerPool,選擇既有 sun-appserver-samples 資料庫,密碼 pbpublic。jdbc/cmpcustomer,關聯上述 Pool。sun-ejb-jar.xml,CMP Resource JNDI 名稱設為 jdbc/cmpcustomer。Run → Run Main Project。IDE 打包 EAR、部署至伺服器、啟動應用。適用於:專案不符 BluePrints、模組獨立開發、需保留既有 Ant 腳本。
File → New Project → Enterprise → EJB Module with Existing Sources。cmpcustomer/cmpcustomer-ejb。Existing Sources and Libraries 頁可調整多來源根目錄、庫資料夾。build.xml、nbproject/project.properties 等標準檔案。File → New Project → General → EJB Module with Existing Ant Script。build.xml。core、Clean → clean、Run → update、Javadoc → javadocs)。cmpcustomer/cmpcustomer-ejb/src/conf,伺服器資源資料夾 cmpcustomer/cmpcustomer-ejb/setup。Sun Java Systems Application Server 8.1,J2EE 版本 1.4,來源層級 JDK 1.4。lib/j2ee.jar(供程式碼補全、重構使用)。Build Project、Generate Javadoc 產出後,Properties → Output 指定建構輸出與 Javadoc 目錄,建立專案間依賴基礎。| 問題 | 原因 | 解決 |
|---|---|---|
| 來源目錄紅色高亮、Finish 按鈕灰色 | 該目錄已屬於另一開啟專案 | 關閉衝突專案 → 退出 IDE → 刪除衝突專案資料夾 → 重啟 IDE |
Ant 腳本引用相對路徑 common-ant.xml,Samples 目錄位置異動 | 編輯 build.xml 修正 common-ant.xml 絕對路徑 | |
| 伺服器資源未部署或 JNDI 名稱不符 | 確認 Sun Resources 節點下 Connection Pool/Resource 已部署至目標伺服器 | |
| Web 模組類路徑缺少 EJB 介面 JAR | War 專案 Libraries 加入 EJB 專案(專案依賴),非來源目錄 |
掌握專案導入與配置技巧,讓 NetBeans 成為 J2EE 開發的高效利器,而非單純的編輯器。