JBuilder 7 憑藉強大的 EJB 視覺化開發工具,讓複雜的企業級應用開發變得高效直觀。本文以 JBoss + Tomcat 為運行環境,手把手示範從專案建立、EJB 模組開發、Web 應用建立、JNDI 配置到 EAR 封裝部署的完整流程。
C:\examples,移除原有 XML 配置檔interest,版本選 EJB 2.0InterestSessionorg.jboss.docs.interest.InterestBeanorg.jboss.docs.interest.InterestHomeorg.jboss.docs.interest.Interestejb-jar.xml 內容,Rebild 自動生成 JARinterestweb (對應 URL: https://localhost:8080/interestweb/),目錄指向 examples\weborg.jboss.docs.interest,類別名 InterestServlet,複製原始邏輯碼覆蓋home.jsp,複製原 home.html 內容編輯 web.xml,重點在 <ejb-ref> 區段:
<ejb-ref>
<ejb-ref-name>ejb/Interest</ejb-ref-name> <!-- 對應 Servlet 中 lookup 名稱 -->
<ejb-ref-type>Session</ejb-ref-type>
<home>org.jboss.docs.interest.InterestHome</home>
<remote>org.jboss.docs.interest.Interest</remote>
<ejb-link>Interest</ejb-link> <!-- 對應 ejb-jar.xml 中 ejb-name -->
</ejb-ref>
注意:<url-pattern> 需與前端表單 action 大小寫一致 (範例中修正為 /InterestServlet);設定 welcome-file-list 為 home.jsp。
application.xml (對應專案樹 examples.eargrp)examples.earJBoss/server/default/deploy瀏覽 https://localhost:8080/interestweb/,輸入參數提交,若顯示:
Servlet interface to EJB
Calling EJB...
Interest on 1000.0 units, at 10.0% per period, compounded over 2.0 periods is: 210.00000000000023
即代表 J2EE 應用成功建置部署。此流程展示 JBuilder 7 將繁瑣的 XML 配置、封裝部署自動化,讓開發者專注業務邏輯。