將 Web 應用程式部署到 Liberty

透過部署 helloworld.war 應用程式,您可以瞭解伺服器配置在 Liberty 中如何變更。

開始之前

helloworld.war 應用程式利用簡式 Servlet,將訊息顯示在您的瀏覽器中。 您可以建立任何其他要顯示的訊息。 在 Liberty 文件中,沒有撰寫應用程式的說明。

關於這項作業

當您利用開發人員工具,將 Web 應用程式部署到 Liberty 時,server.xml 檔中與應用程式相關的所有配置都會自動啟用。不過,您也可以完成下列步驟來手動配置 server.xml 檔。

這個範例使用 helloworld.war 應用程式,可以利用 http://localhost:9090/helloworld 來存取。在本例中,會建立 Liberty 伺服器實例,然後將其預設 HTTP 埠變更為 9090,接著在其中部署應用程式。

程序

  1. 利用 server create hwserver 指令來建立伺服器,名稱為 hwserver
  2. helloworld.war 應用程式複製到 /usr/servers/hwserver/apps 目錄中;這個目錄已在步驟 1 由 server create 指令建立。
  3. 在由 server create 指令建立的 server.xml 檔中,以 httpPort="9090" 取代屬性值 httpPort="9080",以便將伺服器 hwserver 的預設 HTTP 埠變更為 9090:
    <server description="new server">
    
      <!-- Enable features -->
        <featureManager>
          <feature>jsp-2.2</feature>
        </featureManager>
    
        <httpEndpoint id="defaultHttpEndpoint"
          host="localhost"
          httpPort="9090"
          httpsPort="9443" />
    </server>
  4. 依照下列方式之一,更新 server.xml 來配置應用程式:
    • 使用 webApplication 元素來定義應用程式:
      <server description="Hello World Server">
      
       <featureManager>
         <feature>servlet-3.0</feature>
       </featureManager>
      
      <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9090" />
      
      <webApplication contextRoot="helloworld" location="helloworld.war" />
      
      </server>
    • 使用 application 元素來定義應用程式:
      <server description="Hello World Server">
      
       <featureManager>
         <feature>servlet-3.0</feature>
       </featureManager>
      
      <httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9090" />
      
      <application context-root="helloworld" type="war" id="helloworld"
          location="helloworld.war" name="helloworld"/>
      
      </server>

    除了 context-roottypewebApplication 元素所用的子元素,可以與 application 元素相同。就 context-root 來說,這兩個元素不會一起運作,如果 applicationwebApplication 元素都定義了相同的 context-root,只會使用其中一個,且會顯示錯誤。

    context-root 屬性會指定已部署之應用程式的進入點。已部署之應用程式的進入點,取決於下列優先順序:
    • server.xml 檔中的 context-root
    • application.xml(EAR 應用程式)
    • ibm-web-ext.xml(Web 應用程式)
    • server.xml 檔中應用程式的 name(Web 應用程式)
    • Manifest.MF(WAB 應用程式)
    • 相對於 Liberty drop-ins 目錄的目錄名稱或檔名
    註: 在應用程式伺服器的 server.xml 配置中,application 元素可以包含 context-root 標籤。這個 context-root 標籤適合與 type="war" 標籤併用。如果是其他所有的應用程式類型,context-root 元素就沒有作用。

    如果是 EAR 應用程式或 EBA 應用程式,不可能置換 context-root。唯一可執行置換的是獨立式 WAR 檔或 webApplication

  5. 利用 server run hwserver 指令,在前景啟動伺服器
  6. http://localhost:9090/helloworld 測試應用程式。
  7. 選擇性的: 如果不需要伺服器,請停止伺服器

指示主題類型的圖示 作業主題



「時間戳記」圖示 前次更新: 2016 年 11 月 30 日
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-libcore-mp&topic=twlp_dep_war
檔名:twlp_dep_war.html