| 軟體 | 版本 | 備註 |
| JBuilder | 4 Enterprise | 含 AppServer 4.1 |
| JDK | 1.2 / 1.3 | 專案設定指向 1.2 |
| Java Plug-in | 1.2.2_005 | jre-1_2_2_005-win.exe |
| OS | Windows 2000 Professional | |
| 瀏覽器 | IE 5 | |
步驟總覽
- 建立專案,設定 JDK 1.2
- 定義 IDL 介面
- 生成伺服器端骨架並實作
- 建立 Applet 客戶端
- 編譯打包 JAR
- 啟動 AppServer 與 Gatekeeper
- 部署 HTML/JAR 並測試
關鍵程式碼片段
IDL 定義
module Module1 {
interface Interface1 {
long operation1();
};
};
伺服器端實作
public int operation1() {
ServerMonitor.log("(" + _name + ") Interface1Impl.operation1()");
return (int) System.currentTimeMillis();
}
Applet 客戶端核心
public class Applet1 extends JApplet {
private Module1.Interface1 _interface1;
private String _name = "Interface1";
public void init() {
jbInit();
ORB orb = ORB.init(this, null); // 關鍵:傳入 Applet 參考
_interface1 = Module1.Interface1Helper.bind(orb, "/" + _name + "_poa", _name.getBytes());
}
void jButton1_actionPerformed(ActionEvent e) {
jLabel1.setText(String.valueOf(_interface1.operation1()));
}
}
部署關鍵檔案與指令
啟動 AppServer
ias -javahome c:\jbuilder4\jdk1.3
部署目錄檔案 (\Inprise\AppServer\html\public_html\)
untitled1.jar (專案打包)
vbjorb.jar (VisiBroker ORB 執行庫)
Applet1.html (原始產出)
jre-1_2_2_005-win.exe (Java Plug-in 安裝程式)
HTML 版本 1:標準 APPLET 標籤 (Applet2.html)
<APPLET CODEBASE="."
ARCHIVE="vbjorb.jar, untitled1.jar"
CODE="untitled1.Applet1.class"
WIDTH="400" HEIGHT="300">
<PARAM NAME="org.omg.CORBA.ORBClass" VALUE="com.inprise.vbroker.orb.ORB">
<PARAM NAME="vbroker.orb.alwaysTunnel" VALUE="true">
<PARAM NAME="vbroker.orb.gatekeeper.ior" VALUE="">
</APPLET>
HTML 版本 2:OBJECT 標籤支援 Java Plug-in (Applet3.html)
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH="400" HEIGHT="300"
codebase="https://127.0.0.1:8080/jre-1_2_2_005-win.exe#Version=1,2,2,0">
<PARAM NAME="CODE" VALUE="untitled1.Applet1.class">
<PARAM NAME="CODEBASE" VALUE=".">
<PARAM NAME="ARCHIVE" VALUE="untitled1.jar, vbjorb.jar">
<PARAM NAME="org.omg.CORBA.ORBClass" VALUE="com.inprise.vbroker.orb.ORB">
<PARAM NAME="vbroker.orb.alwaysTunnel" VALUE="true">
<PARAM NAME="vbroker.orb.gatekeeper.ior" VALUE="">
</OBJECT>
執行驗證步驟
- 啟動 Gatekeeper:
start gatekeeper
- 取得 IOR:
printior gatekeeper.ior (記錄 IP 位址)
- AppletViewer 測試:
appletviewer https://[IP]:8080/Applet2.html
- IE 5 測試:
https://[IP]:8080/Applet3.html
關鍵技術點解析
| 項目 | 說明 |
| ORB.init(this, null) | Applet 環境下需傳入 Applet 參考以取得 CODEBASE |
| alwaysTunnel=true | 強制使用 HTTP 通道穿透防火牆 (IIOP over HTTP) |
| Gatekeeper | VisiBroker 防火牆代理,統一對外埠口 (預設 8080) |
| vbjorb.jar | 客戶端必備 ORB 實作,含 GIOP/IIOP 協定處理 |
| Java Plug-in | 瀏覽器使用 Sun JVM 而非內建 JVM,確保 CORBA API 相容 |
常見問題排查
ClassNotFoundException:確認 ARCHIVE 順序 (vbjorb.jar 優先)、大小寫
COMM_FAILURE:檢查 Gatekeeper 是否啟動、IOR 是否正確、防火牆埠口
NO_PERMISSION:Applet 未簽署或安全策略阻擋,需 .java.policy 授權
- IE 顯示紅叉:Java Plug-in 未安裝、版本不符、
codebase URL 錯誤
現代化遷移建議
CORBA/Java IDL 已逐漸被 REST/gRPC 取代。遷移路徑:
- IDL 介面 → Protobuf/gRPC 服務定義
- VisiBroker ORB → gRPC Java (Netty 傳輸)
- Applet 客戶端 → 獨立 JavaFX/Swing 應用或 Web 前端 (gRPC-Web)
- AppServer → Spring Boot / Quarkus 微服務
- Gatekeeper → API Gateway (Kong, Envoy, Spring Cloud Gateway)
- 上一篇文章: Applet 使用 JDBC-ODBC 橋接器連線 MSSQL Server 實作範例
- 下一篇文章: Java 實作二維向量 (Vector of Vector) 多種方案比較
Copyright ©
程式碼之家 All Rights Reserved