使用 Ant 建置工具來建置 Plants by WebSphere



J2EE 可攜性
重新建置這個展示區中所附的範例
開始使用
識別目錄結構
重新建置和安裝範例

J2EE 可攜性

在 J2EE 平台上開發應用程式其中一個最大的好處是具備可攜性。「範例展示區」中的所有範例程式都是在工作站上開發, 且不需變更任何一行 Java 程式碼,即可在 z/OS 和 iSeries 系統上執行。藉由將 J2EE 應用程式建置在 Intel 或 UNIX 系統上, 開發人員即不需面臨將 EBCDIC 轉換成 ASCII 或將 ASCII 轉換成 EBCDIC 檔案的苦差事。由於工具的可用性, 開發人員可輕鬆在開發工作站上進行撰寫和測試,並將企業保存檔 (EAR) 安裝在 z/OS 和 iSeries 系統上。

重新建置這個展示區中所附的範例

WebSphere Application Server (Application Server) for z/OS 和 iSeries 的每一個客戶,都能夠使用多平台的 Application Server 媒體。如果您將 WebSphere Application Server Base 基礎產品和範例安裝在此套件所支援的其中一個平台上, 可看到相同的展示區。不過,例外的是當您按一下 sample_name > 使用 Ant 來建置 > 平台 > 重新建置和安裝 sample.ear 檔, 將會指示您在該平台上重新建置 EAR 檔。由於 EAR 檔中的文字檔(XML、xmi、JavaServer Pages (JSP) 檔等)必須採 ASCII 格式, 因此可輕鬆在 ASCII 機器上編輯這些檔案。如果您在 ASCII 機器上進行變更,之後您可以將最後結果的 EAR 檔部署和安裝在 z/OS 和 iSeries 平台上,而不需將 EBCDIC 轉換成 ASCII。 

開始使用

將 WebSphere Application Server 安裝在您所選的分散式平台上, 並指出要安裝應用程式伺服器的範例應用程式。

在試著修改或重新建置範例前,先備份 <profile_root>/samples  目錄。建立 samples 目錄的 zip 檔。您可以解壓縮 zip 檔,將 samples 目錄還原成原始狀態。

識別目錄結構

範例安裝在下列目錄中:


<profile_root>/samples/src/PlantsByWebSphere 內含 Plants by WebSphere 範例的範例程式碼。
<profile_root>/samples/lib/PlantsByWebSphere 內含 Plants by WebSphere 範例的 Web 保存檔 (WAR)、Java 保存檔 (JAR) 和最終的 PlantsByWebSphere.ear 檔。這個目錄是在重建 Plants by WebSphere 範例後建立的。
<profile_root>/samples/javadoc/PlantsByWebSphere 內含 Javadoc 文件。這個目錄是在重建 Plants by WebSphere 範例後建立的。
<profile_root>/samples/bld/PlantsByWebSphere 內含所產生的類別檔。請使用這些類別檔來產生最終的 PlantsByWebSphere.ear 檔。 這個目錄是在重建 Plants by WebSphere 範例後建立的。

重新建置和安裝範例

Plants by WebSphere 範例會隨 WebSphere Application Server 自動安裝。在使用 Plants by WebSphere 範例前, 不需先建置。下列指示說明重新建置範例的相關步驟,以及和修改有關的其他資訊。


執行範例建置 Script
轉送已重新建置的 PlantsByWebSphere.ear
移除並重新安裝 PlantsByWebSphere.ear

執行範例建置 Script

若要重建這個範例,請確認 profile_root/bin 位於 PATH 環境變數中。 請遵循下列步驟來執行範例建置 Script,以重新建置範例:

  1. 開啟命令提示字元。
  2. 在指令行中,切換至 <profile_root>/samples/src/PlantsByWebSphere 目錄。
  3. 執行範例建置 Script:

  4. 輸入下列指令:


    <profile_root>\samples\bin\PlantsByWebSphere\buildplantsby.bat


    • 若為 Windows 開發平台,請輸入下列指令:

      <profile_root>\samples\bin\PlantsByWebSphere\buildplantsby.bat


    • 若為 UNIX 和 Linux 開發平台,請輸入下列指令:

      . <profile_root>/samples/bin/PlantsByWebSphere/buildplantsby.sh

此時會建置範例。

位於 profile_root/samples/bin/PlantsByWebSphere 目錄中的 buildplantsby.batbuildplantsby.sh Script, 會設定適當的類別路徑資訊並執行 Ant 建置公用程式。Ant 會讀取說明如何建置範例的 build.xml 檔。有關 Ant 的其他文件, 請參閱 Jakarta 網站

重要資訊 在建置程序期間,只會重新建置已變更的類別檔。其餘的類別檔會重新包裝成新的 EAR 檔。

轉送已重新建置的 PlantsByWebSphere.ear

請按照下列指示,使用「檔案傳送通訊協定 (FTP)」將二進位 EAR 檔傳送至 z/OS 或 iSeries 伺服器。

  1. <profile_root>/samples/lib/PlantsByWebSphere 目錄中找出已重新建置的 EAR 檔
  2. 從開發平台開啟和 WebSphere Application Server for z/OS 或 iSeries 的 FTP 階段作業
  3. 切換至 <profile_root>/samples/lib/PlantsByWebSphere 目錄
    如果該目錄不存在,您可能需要建立它。
  4. 如果 PlantsByWebSphere.ear 檔存在,請刪除它,以便寫入更新檔。
    del PlantsByWebSphere.ear
  5. bin
  6. put PlantsByWebSphere.ear
  7. quit

移除並重新安裝 PlantsByWebSphere.ear

依預設,Plants by WebSphere 範例安裝在 profile_root/installedApps/<cell name> 目錄中,其中 <cell name> 是安裝應用程式的 Cell 名稱。請按下列步驟中的說明,重新安裝範例:

  1. 停止應用程式伺服器。
  2. 移除 Plants by WebSphere 範例 EAR 檔:
    1. 輸入下列指令:

      cd <profile_root>\bin
      setupCmdLine

      cd <profile_root>/bin
      . ./setupCmdLine.sh

      z/OS 平台:
      cd <profile_root>/bin
      . ./setupCmdLine.sh

      iSeries 平台:
      cd <profile_root>/bin
      . ./setupCmdLine

      其中 <profile_root> 代表設定檔安裝目錄。
    2. 輸入下列指令來解除安裝應用程式(profile_root/bin 必須在 PATH 中):

      wsadmin -conntype none -lang jython -c "AdminApp.uninstall('PlantsByWebSphere')" 

      wsadmin.sh -conntype none -lang jython -c "AdminApp.uninstall('PlantsByWebSphere')" 

      z/OS 平台:
      wsadmin.sh -conntype none -lang jython -c "AdminApp.uninstall('PlantsByWebSphere')" 

      iSeries 平台:
      wsadmin -conntype none -lang jython -c "AdminApp.uninstall('PlantsByWebSphere')" 
  3. 重新安裝 Plants by WebSphere 範例:
    • 切換至 profile_root/samples/lib/PlantsByWebSphere 目錄。
    • 找出 PlantsByWebSphere.ear 檔。
    • 輸入下列指令:

      wsadmin -conntype none -lang jython -c "AdminApp.install('PlantsByWebSphere.ear',
      	['-appname', 'PlantsByWebSphere', '-usedefaultbindings', '-node', '<node>', '-server', '<server>',
      		'-deployejb', '-deployejb.dbtype', 'DERBY_V10'] )"
      	    
      其中 <node> 是節點名稱,<server> 是要安裝範例的伺服器名稱。

      wsadmin.sh -conntype none -lang jython -c "AdminApp.install('PlantsByWebSphere.ear',
      	['-appname', 'PlantsByWebSphere', '-usedefaultbindings', '-node', '<node>', '-server', '<server>',
      		'-deployejb', '-deployejb.dbtype', 'DERBY_V10'] )"
      	    
      其中 <node> 是節點名稱,<server> 是要安裝範例的伺服器名稱。

      z/OS 平台:
      wsadmin.sh -conntype none -lang jython -c "AdminApp.install('PlantsByWebSphere.ear',
      	['-appname', 'PlantsByWebSphere', '-usedefaultbindings', '-node', '<node>', '-server', '<server>',
      		'-deployejb', '-deployejb.dbtype', 'DERBY_V10'] )"
      	    

      iSeries 平台:
      wsadmin -conntype none -lang jython -c "AdminApp.install('PlantsByWebSphere.ear',
      	['-appname', 'PlantsByWebSphere', '-usedefaultbindings', '-node', '<node>', '-server', '<server>',
      		'-deployejb', '-deployejb.dbtype', 'DERBY_V10'] )"
      	    
      其中 <node> 是節點名稱,<server> 是要安裝範例的伺服器名稱。
  4. 啟動應用程式伺服器。

 

此時,會將已重新建置的 PlantsByWebsphere.ear 檔部署到應用程式伺服器中。