使用 Ant 构建工具构建 Plants by WebSphere 样本



J2EE 可移植性
重建此库中提供的样本
入门
确定目录结构
重建和安装样本

J2EE 可移植性

在 J2EE 平台上开发应用程序的一个主要的优点是可移植性。样本库中的所有样本程序是在工作站上开发的,并且不需要更改一行 Java 代码就可在 z/OS 和 iSeries 系统上运行。通过在 Intel 或 UNIX 系统上构建 J2EE 应用程序,开发者可以消除 EBCDIC 到 ASCII 或 ASCII 到 EBCDIC 文件转换的难题。开发者可使用工具在开发工作站上轻松地编写和测试企业归档(EAR)文件,然后轻松地将它安装在 z/OS 和 iSeries 系统上。

重建此库中提供的样本

每个 WebSphere 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 文件,那么不必进行 EBCDIC 到 ASCII 转换就可以在 z/OS 或 iSeries 平台上部署和安装更改后的 EAR 文件。 

入门

在您选择的分布式平台上安装 WebSphere Application Server,并且指出也安装 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 样本之前构建它。以下指导描述了重建样本的步骤,以及有关修改它们的更多信息。


执行样本构建脚本
传送重建的 PlantsByWebSphere.ear 文件
除去并重新安装 PlantsByWebSphere.ear 文件

执行样本构建脚本

要重建该样本,请验证 profile_root/bin 是否在您的 PATH 环境变量中。按照下列步骤来执行样本构建脚本,它重建样本:

  1. 打开命令提示符。
  2. 在命令行上,转至 <profile_root>/samples/src/PlantsByWebSphere 目录。
  3. 运行样本构建脚本:

  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 脚本设置适当的类路径信息,并执行 Ant 构建实用程序。Ant 读取描述了如何构建样本的 build.xml 文件。请参阅 Jakarta Web 站点以获取有关 Ant 的其他文档。

重要信息 在构建过程中,将仅重建更改过的类文件。其他类文件重新打包到新的 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> 是安装应用程序的单元的名称。按下面描述的步骤重新安装样本:

  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 文件已部署到您的应用程序服务器。