站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题IBM WebSphere 开发者技术期刊 : 使用 Eclipse 富客户端平台和 Rational Application Developer V6 创建 EJB 客户端

IBM WebSphere 开发者技术期刊 : 使用 Eclipse 富客户端平台和 Rational Application Developer V6 创建 EJB 客户端

摘要: This article shows how to build a sample EJB client using the Eclipse Rich Client Platform (RCP), which has become increasingly popularity due to its extensible nature. Besides focusing on how to use Rational Application Developer to build an RCP application, this article also details how to configure an Eclipse RCP application to act as a J2EE application client.

引言

最近几年来,作为编写交互式开发环境(IDE)工具的框架 —— Eclipse 平台的流行程度显著增长。 关于 Eclipse 3.0 版本,同样的技术已经扩展为支持富客户端的开发,给予 Java? 开发者使用有自身感观的可扩展平台编写富客户端代码的能力。

开发富客户端的平台通称 Eclipse Rich Client Platform (RCP)。为什么着重强调富客户端呢?在 n-tiered 体系结构的这几年来,很明显开发给予终端用户丰富的使用浏览器方面经验的应用程序比较困难。基于浏览器的应用程序常常设法通过将 JavaScript 与 HTML 结合起来模拟某种可用性。然而,很明显对于应用程序来说,寻求更丰富的经验比使用更丰富的客户端技术平台要好。同样,Eclipse RCP 给予了开发者创建可扩展客户端应用程序的能力,并且这些可扩展客户端应用程序仍然可以加入到 n-tiered 体系结构中。Eclipse RCP 启用了下一代富客户端,并且是富客户端平台(例如 IBM Workplace Client 技术)的基础。

IBM Rational Application Developer V6 (以前是 IBM WebSphere? Studio Application Developer)是基于 Eclipse 3.0 平台的。这个版本使 J2EE 开发者可以创建与 J2EE 应用程序进行交互的富客户端应用程序。在这篇文章中,我们将使用 Rational Application Developer(以下称之为 Application Developer)中的 Eclipse 3.0 功能构建 Eclipse RCP 客户端,它们调用了配置于 Application Developer 的 WebSphere Application Server 测试环境中的 EJB 组件。

为了构建 Eclipse RCP 应用程序,它调用了运行于 WebSphere Application Server V6 内部的企业 bean,我们将会遵循的一般步骤包括:

为了进行这个练习,您需要:


<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

设置 J2EE 应用程序

首先我们需要做的是安装适合于 WebSphere Application Server 的 IBM Application Client,它已经包括在 WebSphere Application Server V6(如果您没有客户端,您可以将您的配置改变为针对 Application Developer 测试环境中的服务器 JDK)中,并且接下来将应用程序部署到正在运行的 WebSphere Application Server:

  1. J2EE 应用程序客户端是通过使用安装向导界面来安装的。在运行您的 WebSphere 安装的开始界面之后,选择 IBM Client for IBM WebSphere Application Server
  2. 跟随向导,我们将其安装到 C:\WebSphere6ND\AppClient directory 上。下载 ZIP 文件中的 Windows? 批处理(BAT)文件使用了这个类路径;如果您选择了另一个目录,您就必须修改批处理文件转而引用新的目录。图 1 展示了向导的第三个界面您所选择的目录。


  3. 我们同样选择了典型安装,并且输入了 localhost 作为主机名,如图 2 所示。


    接下来我们将会使用 Application Developer 把 EAR 部署到 WebSphere Application Server。(这完全是为了便于构建及测试源于同一工作区的插件;您同样可以只是在独立的 WebSphere Application Server 实例中配置应用程序,随着与它进行对话的已配置的 Eclipse。)
  4. 使用 Start 菜单打开 Application Developer 以及找到到正如 C:\RCPEJBClient\workspace 的工作区,(图 3)。


  5. 关闭默认的 Welcome 页面(图 4)。


  6. 如果您无法在那里缺省地找到自己,就切换到 Switch to the J2EE 透视图 。
  7. 在底部的框中寻找 Servers 视图并且右键单击 WebSphere Application Server v6.0 (图 5)。在这一点上,Application Developer 将会检验 WebSphere Application Server 的缺省实例是否正在运行。


  8. 状态应该恢复到 "Stopped"。右键单击服务器并且选择 Start (图 6)。(您同样可以通过寻找 /runtimes/profiles/default/bin 启动服务器以及执行 startserver server1)。


  9. 当启动了服务器,您就能够通过右键单击服务器及选择 Run administrative console (或打开浏览器并且访问 http://localhost:9060/admin)运行管理控制台,如图 7 中所示。


  10. 以任意用户标识登陆(图 8)。


  11. 展开 Applications 节并且选择 Install New Application (图 9)。


  12. 找到 C:\RCPEJBClient,选择 TemperatureEAR.ear 并且接下来选择 Next (图 10)。TemeratureEAR 应用程序是将温度由摄氏温度转换成华氏温度的简单方法(尽管可能不是很精确)。


  13. 在绑定页面中(图 11),保留缺省值并且选择 Next


  14. 在下一个页面中,应用程序开发流程的第一步,选择 Deploy enterprise beans 然后接下来进入 Step 7 Summary (图 12)。


  15. 在第七步的对话框中,选择 Finish (图 13)。安装需要一分钟或两分钟(图 14)。



    Figure 14. 安装新应用程序的消息

  16. 当安装结束时,选择 Save to Master Configuration (图 15)。


  17. 在保存的对话框中,选择 Save (图 16)。


  18. 现在,我们将会启动应用程序。从 Applications 菜单中,选择Enterprise Applications (图 17)。
    Figure 17. 企业应用程序

  19. 选择 TemperatureEAR 然后接下来选择 Start (图 18)。
    Figure 18. 企业应用程序

  20. 状态栏中的相应图标应该表明了已经启动了应用程序(图 19)。


  21. 管理控制台的注销(图 20)。



<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

创建 RCP 客户端

我们现在已经为创建 RCP 客户端应用程序做好了准备,我们将会通过使用 Plug-in 向导将其用作简单的插件。当创建 RCP 应用程序时,随着对复用性的关注您应该常常创建若干插件。例如,您可以重写该实例来创建关于 J2EE 相关性的单点插件,另一种视图组件,以及 RCP Shell 的一种。这样使得不同的插件可以重用,例如,J2EE 代码。然而,我们将只能拥有这一运用的唯一插件,从根本上限制了这篇文章的作用域。

创建插件项目

  1. 为了在 Application Developer 中创建插件项目,从 J2EE Perspective 中选择File => New => Other (图 21)。


  2. 在 New Project 向导中,查明选择了 Show All Wizards 。扩展 Plug-in Development 然后选择 Plug-in Project (图 22)。


  3. 在这一点上,为了插件的发展您也许会获得启用插件的提示(图 23)。如果是这样的话,选择 OK


  4. 在 Create a new plug-in project 的对话框中(图 24),命名该项目:com.ibm.issw.temperature.form。这是一种很普通的插件命名约定。确定您选择的选项如图 24 所示:
    • 因为您正在添加 Java 代码所以您的插件项目将也会是 Java 项目。
    • 在 Eclipse 3.0 中,您希望使用清单文件设置您的运行时相关性,我们选择使用清单文件。
    选择 Next


  5. 在下一个对话框中,如图 25 所示植入插件数据,接下来选择 Next


  6. 我们将会使用模板构建插件。以后我们将会构建关于视图的插件,选择 Plug-in with a view 然后接下来选择 Next (图 26)。


  7. 在下一个对话框中,我们将会定义关于 View 类的信息。完全按照图 27 所示输入信息,接下来选择 Next


  8. 最后,在 View Features 对话框中(图 28),撤销对所有功能的选择。(我们将会导入我们自己的视图类。)选择 Finish


  9. 档要求我们切换至 Plug-in Development Perspective 的时候(图 29),选择 Yes


导入 J2EE JAR 和 EJB client JAR

现在我们将会把两个 JAR 导入我们的新插件中:

  1. 在 Application Developer 中,右键单击插件项目并且选择 Import (图 30)。


  2. 选择 File System然后接下来选择 Next(图 31)。


  3. 存在若干个您能够获得 j2ee.jar的地方。因为 RCP 将使用运行时的 IBM Application Client for WebSphere Application Server,所以最好使用 JAR,您可以在 /lib 中找到它,如图 32 所示。确定 j2ee.jar 是唯一的选择。(如果您的插件使用其它的 WebSphere API,例如 WebSphere 程序设计模型扩展,您便会同样需要将其导入。否则,您无需导入其它 WebSphere 运行时 JAR;在运行期间,已生成的 EJB 代理服务器代码以及客户端容器代码装载 WebSphere 瘦客户端类库加载器中的类。)如果您没有安装客户端软件,您就能够从 /runtimes/base_v6/lib or /lib 中获得 j2ee.jar


  4. 接下来,我们需要导入 EJB 客户端 JAR,它是需要远程调用 EJB 的代码的专用 JAR 文件。该文件包括了 EJB 客户端接口和已生成的 RMI/IIOP 代码。(如果您正在构建自己的 EJB 应用程序,您可以在 Application Developer 中通过右键单击您的 EJB 项目并且选择 Create EJB Client Jar 生成客户端 JAR)对于这一运用,download file 中提供了 EJB 客户端 JAR。使用文件系统选项导入 JAR 文件,如前所述,转到 C:\RCPEJBClient然后选择 TemperatureEJBClient.jar。(图 33)


  5. 现在我们的插件项目应该包含两个 JAR 文件,如图 34 所示。
    Figure 34. 导入的 JAR

  6. 现在我们需要设置工作区中构建时和编译时类路径。这将会使得插件代码既在 Eclipse IDE 内部又在自动构建过程中成功地进行编译。构建时类路径信息在插件配置编辑器的 Build Section 中更新。选择 Build 选项卡,如图 35 所示。


  7. 定位到 Binary Build 部分(图 36)并且选择如图所示的 JAR 文件。如果您选择执行插件的二进制构建,JAR 需要包括在 Build 之内。对于这一运用,为了运行 Eclipse RCP 应用程序我们将会手动复制插件。


  8. 至于成功编译的代码,您需要将 JAR 添加到编译时类路径上。您可以通过将 JAR 添加到 Build 部分底部的 Extra Classpath Entries 中完成这一内容(图 37)。这样会更新 Eclipse 中的 Project Build Path。


  9. 构建页面的变化更新了 build.properties 文件。您可以通过选择 build.properties 选项卡浏览该文件。
  10. 至于您查找 J2EE 和 EJB 客户端运行时代码的插件代码,它需要添加到插件的运行时类路径。通过插件配置编辑器才能够完成,编辑器已默认的方式打开。(如果不是这样,双击 plug-in.xml 打开。)选择 Runtime 选项卡,并且在运行时程序库部分,选择 Add 按钮(图 37)然后添加您刚刚导入的 JAR。


运行时对话框更新了插件的 MANIFEST.MF 文件。与 J2EE 应用程序很相似,清单定义了运行时类路径。您可以通过定位到 MANIFEST.MF 选项卡查看清单。

使用 SWT 布局小窗口构建视图

现在我们将要构建视图。download file 中提供了 View 类。我们将会导入该类(装载我们通过视图模板生成的类)并且接下来检验代码的相关部分。启动之前,我们需要确定我们的插件所依赖的插件。在视图中我们将会使用标准窗口小部件工具箱(SWT)布局小窗口,因此我们需要设置包括布局小窗口的 Eclipse 插件的相关性。

  1. 选择 Dependencies 选项卡然后选择 Add (图 39)。定位 org.eclispe.ui.forms 插件。


  2. 导入 download file 中提供的 View 类,装载所生成的类。在 src 文件夹下,右键单击com.ibm.issw.temperature.form.views 包,然后选择 Import (图 40)。


  3. 选择 File System 然后接下来选择 Next。浏览目录 C:\RCPEJBClient\View ,并且将三个文件导入包中,如图 41 所示。


  4. 您应该获得将要装载现有类的警告。选择 Yes To All (图 42)。


  5. 打开导入的 TemperatureView.java (图 43)。


  6. 我们将会集中于两种方法(图 44):
    • createPartControl(组合)—— 用于构建您的源自不同 SWT 小窗口的视图。
    • handleEvent() —— 在 inner 类中,提供了当点击 SWT 小窗口命令按钮时调用的逻辑。



  7. createPartContol() 方法如清单 1 所示。代码使用了 FormToolkit 类帮助关于父组件的创建组件;在该情况下,创建所需的标签、按钮、以及文本框,并且将侦听器赋给按钮。侦听器是 View 的内部类。

    清单 1 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

    
    public void createPartControl(Composite parent)
    {
    toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createScrolledForm(parent);
    form.setText(RcpMessages.getString("TemperatureView.Title"));
    GridLayout layout = new GridLayout(2,false);
    form.getBody().setLayout(layout);
    Label label = toolkit.createLabel(form.getBody(),
    "Enter temperature in Celsius: ");
    Text textBox = toolkit.createText(form.getBody(), "", SWT.BORDER);
    GridData gdText = new GridData(8);
    textBox.setLayoutData(gdText);
    Button button = toolkit.createButton(form.getBody(),
    RcpMessages.getString("TemperatureView.Button"),
    SWT.PUSH);
    Label result = toolkit.createLabel(form.getBody(), "");
    result.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    MyListener listener = new MyListener();
    listener.setInput(textBox);
    listener.setResult(result);
    listener.setParent(parent);
    listener.setFormToolkit(toolkit);
    button.addListener(SWT.Selection,listener);
    }
    </td></tr></table>

  8. 内部类的事件处理方法如清单 2 所示。在这一类中,读取了文本框的值以及使用 EJB 客户端 API 调用 EJB。代码查找 EJB home 并且获得远程接口。接下来调用该方法并且用结果值填充结果标签。(要记住,最好将 EJB 调用隐藏在业务委派之后而不是在插件代码中直接调用。对本文来说,我们简化了代码。通常不推荐从 view 中直接调用 EJB。)

    清单 2. <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

    
    public void handleEvent(Event event)
    {
    try
    {
    InitialContext ctx = new InitialContext();
    String jndi = RcpMessages.getString("TemperatureView.JNDIName");
    Object obj = ctx.lookup(jndi);
    
    TempConverterHome homeRef = (TempConverterHome) PortableRemoteObject
    .narrow(obj, TempConverterHome.class);
    TempConverter serviceRef = homeRef.create();
    retVal = serviceRef.celciusToFarenheight(Integer.parseInt(textBox.getText()));
    System.out.println("TemperatureAction.testEJB EJB Successful
    Return=" ++ retVal);
    result.setText(textBox.getText() + " degrees Celsius is
    approximately " +
    Integer.toString(retVal) + " degrees Fahrenheit!");
    
    } catch (Exception th)
    {
    System.out.println("TemperatureAction.testEJB EJB call ex="
    + th);
    th.printStackTrace();
    result.setText(th.getClass().getName() + ": " +
    th.getMessage());
    }
    
    }
    </td></tr></table>

  9. 也许您已经注意到了属性文件是用于避免 EJB JNDI 名称的硬编码以及应用程序服务器的定位。当部署 RCP 应用程序时,您可以将属性文件改变为针对实际的远程 EJB 定位。

    清单 3 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

    
    TemperatureView.JNDIName=ejb/TempConverter
    TemperatureView.Title=Celsius to Fahrenheit Temperature Converter
    TemperatureView.Button=Convert to Fahrenheit
    </td></tr></table>

  10. 当构建插件时,您通常需要将插件添加到您的 plug-in.xml文件并且选择扩展点(在该情况下,您扩展了 View 插件)。对于我们来说这是额外的,因为我们在向导中使用 View 模板。您可以在 Extensions 选项卡中查看或者您可以浏览 plug-in.xml 资源。扩展配置如清单 4 所示。

    清单 4 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

    
    
          
          
          
          
    
    </td></tr></table>

创建您自己的 RCP 工作台和透视图

因为我们正在开发 RCP 应用程序,使用缺省的 Eclipse 工作台,工作台是按照 IDE 定制的,不是很理想的。因此,我们将会构建我们自己的工作台以及透视图。我们将会导入类,下载文件提供了这些类,导入到我们的插件中,接下来向工作台以及透视图的 plug-in.xml 中添加条目。

  1. 右键单击 src 文件夹然后选择 Import (图 45)。


  2. 选择 File system 然后选择 Next。浏览 C:\RCPEJBClient\RCPCode\src 文件夹并且导入三个类,如图 46 所示。


  3. 将类导入 (默认包),它是根(图 47)。


  4. 让我们检验这些类:
    • RcpWorkbenchAdvisor —— 用于创建我们的工作台。代码设置了某种配置,例如大小和标题,并且禁用某种缺省项。

      清单 5 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

      
      public class RcpWorkbenchAdvisor extends WorkbenchAdvisor {
      
      public String getInitialWindowPerspectiveId() {
      return "MyRCPPerspective";
      }
      
      public void preWindowOpen(IWorkbenchWindowConfigurer configurer) {
              super.preWindowOpen(configurer);
              configurer.setInitialSize(new Point(750, 600));
              configurer.setShowCoolBar(false);
              configurer.setShowStatusLine(false);
              configurer.setTitle("Temperature Converter");
      
          }
      
      }
      </td></tr></table>

    • MyRCPPerspective —— 向透视图中添加视图。这是透视图的初始布局。因为我们没有构建文件编辑的插件所以代码也禁用编辑器区域。

      清单 6 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

      
      public class MyRCPPerspective implements IPerspectiveFactory {
      
      public void createInitialLayout(IPageLayout layout) {
      layout.addView("com.ibm.issw.temperature.form.views.TemperatureView",
      IPageLayout.LEFT,0.66f,IPageLayout.ID_EDITOR_AREA);;
      layout.setEditorAreaVisible(false);
      }
      
      }
      </td></tr></table>

    • platform —— RCP 应用程序的主类。创建了工作台并且启动了 RCP 应用程序。

      清单 7 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

      
      public class TempRCPApplication implements IPlatformRunnable {
      
      public Object run(Object args) throws Exception {
      WorkbenchAdvisor workbenchAdvisor = new RcpWorkbenchAdvisor();
      Display display = PlatformUI.createDisplay();
      try {
      int returnCode = PlatformUI.createAndRunWorkbench(display,workbenchAdvisor);
      if(returnCode == PlatformUI.RETURN_RESTART)
      {
      return IPlatformRunnable.EXIT_RESTART;
      }
      else
      {
      return IPlatformRunnable.EXIT_OK;
      }
      
      } finally {
      display.dispose();
      }
      }
      
      }
      
      </td></tr></table>

  5. 关于当前添加的代码,我们需要将它添加到我们的 plug-in.xml 中去。选择 Extension 选项卡,然后接下来选择 Add (图 48)。


  6. 因为我们在编写应用程序,所以我们需要扩展 org.eclipse.core.runtime.applications(图 49)。


  7. 选择 Finish
  8. 在 Extension Details 对话框中,添加作为标识的 RcpApplication (图 50)。


  9. 右键单击扩展点并且选择 New => application (图 51)。


  10. 右键单击 (application) 然后选择 New => run (图 52)。


  11. 在 Extension Element Details 对话框中,浏览 TempRCPApplication 类(图 53)。.


  12. 添加透视图、添加其它扩展并且选择 org.eclipse.ui.perspectives 扩展点(图 54)。


  13. 右键单击该点并且选择 New => perspective (图 55)。


  14. 在 Extension Element Details 中,如图 56 所示浏览 perspective 类:


  15. 更新标识以符合类名(图 57):


  16. 现在扩展应该表现为图 58 所示。通过选择 File => Save Ctrl-S 保存插件配置。


换句话说,您可以通过手动直接将它添加到 plug-in.xml 文件中,如清单 8 所示。附加的代码如黑体字所示:

清单 8 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>




   
      
      
      
      
   
   
      
         
      
   
   
      
   


</td></tr></table>


<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

测试您的 RCP EJB 客户端

现在我们已经为运行 RCP EJB 客户端做好了准备。我们首先将会从 Application Developer 内部进行 RCP 应用程序的单元测试。接下来我们将会导出插件并且为在开发环境外部运行对其进行设置。

Application Developer 内部测试

关于 Eclipse 3.0 版本,您可以为了运行插件创建 launch configurations。这些 launch configuration 为了使用 WebSphere V6 JRE 需要进行设置(包括了 IBM Application Client for WebSphere Application Server 以及 WebSphere Application Server),通过 Perspective Preferences 进行添加。然而,不是使用 Eclipse,而是我们将会使用Application Developer,其中已经安装了 JRE。

  1. 从 Application Developer 的主菜单中选择 Run =>Run...。(图 59)。


  2. 在 Launch Configuration 向导中选择 Run-time workbench 以及 New (图 60)。


  3. 为 MyRCPClient 配置命名。在 Program to Run 部分中,选择您的插件,对于运行应用程序,选择 com.ibm.issw.temperature.form.RcpApplication,对于 JRE,选择 WebSphere v6 JRE(图 61)。


  4. 对于 VM arguments,通过 C:\RCPEJBClient\Snippet1.txt 所提供的代码(清单 9)输入如图 61 所示代码。还不能运行。VM arguments 是针对安装 IBM Application Client for WebSphere Application Server 目录。如果您将它安装在不同的目录下,是用那个目录。否则,使用 Application Developer 中定位于 /runtimes/base_v6 的 WebSphere 实例。

    清单 9 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

    
    -Djava.naming.provider.url=corbaloc::localhost
    -Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
    -Dserver.root=C:\WebSphere6ND\AppClient
    -Dcom.ibm.CORBA.ConfigURL=file:C:\WebSphere6ND\AppClient/properties/sas.client.props
    -Djava.ext.dirs="C:\WebSphere6ND\AppClient\java\jre\lib\ext;
    C:\WebSphere6ND\AppClient\java\jre\lib;C:\WebSphere6ND\AppClient\classes;
    C:\WebSphere6ND\AppClient\lib;C:\WebSphere6ND\AppClient\lib\ext;
    C:\WebSphere6ND\AppClient\properties
    </td></tr></table>

  5. 在 Plug-in 选项卡上,我们需要包括我们的新插件所依赖的插件。我们能够容易地通过遵循图 62 所示的点击顺序完成这一内容。


  6. 选择 Apply,接下来选择 Run。客户端应该与图 63 相似。


  7. 输入值,然后选择 Convert to Farenheit
  8. 应该显示结果,与图 64 相似。(首次引用将会比后来的引用花费更长的时间,因为它需要与 WebSphere Application Server 建立初始的通信。)


构建并运行 Application Developer 外部的 RCP 应用程序

为了运行 Application Developer 外部的 RCP 应用程序,我们将会需要使用导出插件向导。在 Eclipse 3 版本中,不存在任何 RCP 应用程序的导出机制,但您可以使用二进制构建完成这一流程。出于教学的目的,我们将亲自进行部署。

  1. 右键单击插件项目并且选择 Export (图 65)。


  2. 在 Export 对话框中(图 66)选择 deployable plug-ins and fragments,然后选择 Next


  3. 从可部署的插件及片断对话框中选择我们的插件,选择将其作为 directory structure 进行配置,接下来在目录上对其进行配置如图 67 所示。选择 Finish


  4. 将要运行 PDE 导出向导(图 69)。


  5. 我们需要 BAT 文件来启动应用程序。为简单起见,由 download file 中提供。将 BAT 文件从 C:\RCPEJBClient\MyRCPApp.bat 复制到您导出插件的目录。
  6. BAT 文件将会使用应用程序客户端 JRE(假设 IBM Client for WebSphere Application Server位于 C:\WebSphere6ND\AppClient;否则,为了替换目录通过针对应用程序客户端更新初始的变量而更新脚本,或者针对 WebSphere Application Server 如果您不使用客户端的话)。

    (我们在测试关于 WebSphere Application Server Base 的 RCP 应用程序。如果,在生产中,您将会调用部署到集群的 EJB 应用程序,参数 Djava.naming.provider.url=corbaloc::localhost 应该拥有表示像这样一个集群:corbaloc:::,:: 的 URL。)

    清单 10 <table bgcolor="#eeeeee" width="100%" cellpadding="5" cellspacing="0" border="1"><tr><td>

    
    set WAS_CLIENT_HOME=C:\WebSphere6ND\AppClient
    
    start %WAS_CLIENT_HOME%\java\jre\bin\javaw
    -Djava.naming.provider.url=corbaloc::localhost 
    -Djava.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory
    -Dserver.root=%WAS_CLIENT_HOME% 
    -Dcom.ibm.CORBA.ConfigURL=file:%WAS_CLIENT_HOME%/properties/sas.client.props 
    -Djava.ext.dirs=%WAS_CLIENT_HOME%\java\jre\lib\ext;%WAS_CLIENT_HOME%\java\jre\lib;%WAS_CLIENT_HOME%\
    classes;%WAS_CLIENT_HOME%\lib;%WAS_CLIENT_HOME%\lib\ext;%WAS_CLIENT_HOME%\properties
    -cp startup.jar org.eclipse.core.launcher.Main 
    -application com.ibm.issw.temperature.form.RcpApplication
    </td></tr></table>

  7. 因为我们亲自导出了插件,所以需要从我们的 Eclipse 安装目录复制 startup.jar 以及基础插件。在 Application Developer 之中,基础 Eclipse 定位到 Application Developer 安装目录下的 eclipse 目录(图 69)。


  8. 粘贴 startup.jar 到配置插件的目录。


  9. 接下来,复制所需插件:
    • org.eclipse.core.expressions_3.0.0
    • org.eclipse.core.runtime_3.0.1
    • org.eclipse.help_3.0.0
    • org.eclipse.jface_3.0.0
    • org.eclipse.osgi_3.0.1
    • org.eclipse.platform_3.0.1.1
    • org.eclipse.swt.win32_3.0.1
    • org.eclipse.swt_3.0.1
    • org.eclipse.ui.forms_3.0.0
    • org.eclipse.ui.workbench_3.0.1.1
    • org.eclipse.ui_3.0.1
    • org.eclipse.update.configurator_3.0.0
    记住,您可以使用二进制构建或脚本化 ANT 构建使该流程自动化。


  10. 通过 MyRCPApp.bat 运行应用程序。(再一次,初始请求会比后来的请求花费更长的时间。)



<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

结束语

这篇文章描述了如何使用 Eclipse Rich Client Platform (RCP)构建 EJB 客户端应用程序。Eclipse 平台包括了大量的窗口、视图、框架(例如 Eclipse Modeling Framework),以及其它能够用于构建强大客户端应用程序的的扩展。了解如何使 Eclipse RCP 应用程序与 WebSphere Application Server 一体化对于构建一体化客户端应用程序是必不可少的。


<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

致谢

作者由衷地感谢 Wayne Beaton 对本篇文章的审阅与改进。



<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

下载

<table width="100%" class="data-table-1" cellspacing="0" cellpadding="0" border="0"><tr><th>描述</th><th>名字</th><th style="text-align:right;">大小</th><th>下载方法</th></tr><tr><td class="tb-row">Sample Rich Client Platform application</td><td nowrap="nowrap">RCPEJBClient.zip</td><td style="text-align:right;" nowrap="nowrap">1.6 MB</td><td nowrap="nowrap"> ?FTP|HTTP</td></tr></table><table cellspacing="0" cellpadding="0" border="0"><tr valign="top"><td colspan="5"></td></tr><tr><td></td><td>关于下载方法的信息</td><td></td><td></td><td>Get Adobe® Reader®</td></tr></table>
<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>


<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>

作者简介<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td colspan="3"></td></tr><tr align="left" valign="top"><td>

</td><td></td><td width="100%">

Roland Barcia 是位于纽约/新泽西州 Metro 区的 IBM Software Services for WebSphere 的 IT 顾问专家。他是书籍 IBM WebSphere: 部署和高级配置 的作者之一。

</td></tr></table>
<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td colspan="3"></td></tr><tr align="left" valign="top"><td>

</td><td></td><td width="100%">

Patrick Nogay 是 IBM Software Services for WebSphere 的 IT 顾问专家。

</td></tr></table>

<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>
</td></tr></table><table class="no-print" cellspacing="0" cellpadding="0" align="right"><tr align="right"><td>
<table border="0" cellpadding="0" cellspacing="0"><tr><td valign="middle">
</td><td valign="top" align="right"></td></tr></table></td></tr></table>


↑返回目录
前一篇: 集成 DB2 与 Apache Geronimo
后一篇: Apache Beehive 相关介绍