環境基線
- J2EE SDK 1.4 (Sun RI)
- PointBase 資料庫 (內嵌)
- Ant 1.6+ (SDK 內建 `asant` 腳本)
- Domain: `domain1` (預設)
各範例安裝執行速查表
1. Duke's Bookstore — Web 應用完整範例
cd J2EE1.4/samples/webapps/bookstore/bookstore1
# 1. 清理與編譯
asant clean
asant core
# 2. 啟動 PointBase 並部署 (建立資料表、載入資料)
# 另開終端機:
%POINTBASE_HOME%/tools/serveroption/startserver.bat
asant deploy
# 3. 執行驗證
# 瀏覽器: https://localhost:8080/bookstore1/enter
# 4. 產生 Javadoc
asant javadocs
2. Stateless Session Bean — HelloWorld
# 位置
J2EE1.4/samples/ejb/stateless/simple/src
# 部署後驗證
https://localhost:8080/helloworld
3. Stateful Session Bean — CartBean (購物車)
# 位置
J2EE1.4/samples/ejb/stateful/simple/src
# 執行應用客戶端
cd %J2EE_HOME%/domains/domain1/applications/J2EE-apps/stateful-simple
appclient -client stateful-simpleClient.jar -name CartClient -textauth
# 登入: guest / guest123
4. CMP Entity Bean — Customer
# 位置
J2EE1.4/samples/ejb/cmp/cmpcustomer/src
# 必須先在管理主控台建立資源
# 1. JDBC 資源: jdbc/cmpcustomer
# 2. 連線池: cmpcustomer-pool
# 執行驗證
https://localhost:8080/customer/
5. BMP Entity Bean — StorageBin
# 位置
J2EE1.4/samples/ejb/bmp/simple/src
# 執行應用客戶端
cd %J2EE_HOME%/domains/domain1/applications/J2EE-apps/bmp-simple
appclient -client bmp-simpleClient.jar -name StorageBinClient -textauth
6. Message Driven Bean (MDB) — SimpleMessage
# 位置
J2EE1.4/samples/ejb/mdb/simple/src
# 必須先在管理主控台建立 JMS 資源
# 1. Connection Factory: jms/MyQCF (javax.jms.QueueConnectionFactory)
# 2. Destination: jms/MyQueue (javax.jms.Queue)
# 執行應用客戶端
cd %J2EE_HOME%/domains/domain1/applications/J2EE-apps/mdb-simple
appclient -client mdb-simpleClient.jar -name SimpleMessageClient -textauth -xml %J2EE_HOME%/domains/domain1/config/sun-acc.xml
已安裝範例與存取路徑總覽
| 範例 | 類型 | 存取 URL / 指令 |
| Duke's Bookstore | Web App | https://localhost:8080/bookstore1/enter |
| Stateless SessionBean | EJB | https://localhost:8080/helloworld |
| Stateful SessionBean | EJB | appclient -client stateful-simpleClient.jar -name CartClient -textauth |
| CMP Customer | EJB | https://localhost:8080/customer/ |
| BMP StorageBin | EJB | appclient -client bmp-simpleClient.jar -name StorageBinClient -textauth |
| MDB SimpleMessage | EJB | appclient -client mdb-simpleClient.jar -name SimpleMessageClient -textauth -xml .../sun-acc.xml |
關鍵基礎設施啟動順序
- PointBase 資料庫 Server (CMP/BMP 依賴)
- J2EE Server (`j2ee -verbose` 觀察埠衝突)
- 部署應用 (`asant deploy` 或管理主控台)
- 執行客戶端 / 瀏覽器驗證
常見安裝問題與解決
| 問題 | 原因 | 解決 |
| 埠 1050/8000 衝突 | 其他程序佔用命名服務/Web 埠 | 修改 config/orb.properties 變更預設埠 |
| XML 解析錯誤 FactoryConfigurationError | JRE lib/jaxp.properties 或 ext/jaxp.jar 衝突 | 刪除 jre/lib/jaxp.properties、jre/lib/ext/jaxp.jar |
| ant 找不到 build.xml | 工作目錄錯誤 | cd 到範例根目錄再執行 ant |
| 編譯不能解析符號 | J2EE_HOME 環境變數未設定 | 設定 J2EE_HOME 指向 SDK 安裝目錄 |
| appclient 找不到 Client JAR | 未正確部署/打包 | 重新依教學步驟部署應用 |
| 登入失敗 | 帳號密碼錯誤 | 預設 guest / guest123 |
| JNDI 名稱不匹配 | 部署描述符與程式碼不一致 | 檢查 ejb-jar.xml / sun-ejb-jar.xml JNDI 名稱 |
驗證工具:Verifier
- DeployTool 內建:Tools → Verifier
- 獨立執行:`verifier` (GUI) 或 `verifier -c` (命令列)
- 檢查:部署描述符語法、介面與實作一致性、資源引用完整性
參考資源
- 官方文檔:`J2EE1.4/samples/docs/list.html`
- EAR 檔對照:`J2EE1.4/samples/ears/` 含預建好的 EAR 供比對
- 清理重來:`j2ee -stop && cleanup && j2ee -verbose`