IBM WebSphere Developer Technical Journal: Creating EJB clients using the Eclipse Rich Client Platform and Rational Application Developer V6

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 IBM® 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.

Roland Barcia (barcia@us.ibm.com), Consulting IT Specialist, IBM Software Services for WebSphere

Roland Barcia is a Consulting IT Specialist for IBM Software Services for WebSphere in the New York/New Jersey Metro area. He is co-author of the book IBM WebSphere: Deployment and Advanced Configuration.



Patrick Nogay (nogay@us.ibm.com), Consulting IT Specialist, IBM Software Services for WebSphere

Patrick Nogay is a Consulting IT Specialist for IBM Software Services for WebSphere.



26 January 2005

Also available in Chinese Russian

Introduction

Over the last few years, the Eclipse platform has grown dramatically in popularity as a framework for writing interactive development environment (IDE) tools. With release of Eclipse 3.0, that same technology has been expanded to support the development of rich clients, giving Java™ developers the ability to write rich client code using an extensible platform with a native look and feel.

The platform for developing rich client is known as the Eclipse Rich Client Platform (RCP). Why the refocus on rich clients? Over the years of n-tiered architecture, it became evident that it was difficult to develop applications that give the end user a rich experience with a browser. Browser-based applications often tried to mimic certain usability by combining JavaScript with HTML. However, it was clear that applications looking for a richer experience were better off using a richer client technology platform. As such, Eclipse RCP gives developers the ability to create extensible client applications that can still participate in an n-tiered architecture. Eclipse RCP enables the next generation rich client, and is the basis for rich client platforms such as IBM Workplace Client technology.

IBM Rational Application Developer V6 (formerly, IBM WebSphere® Studio Application Developer) is built on the Eclipse 3.0 platform. This gives J2EE developers the opportunity to create rich client applications that interact with J2EE applications. In this article, we will use the Eclipse 3.0 features in Rational Application Developer (hereafter referred to as Application Developer) to build Eclipse RCP clients that call EJB components deployed in the WebSphere Application Server test environment inside Application Developer.

To build an Eclipse RCP application that calls an enterprise bean running inside WebSphere Application Server V6, the general steps we will follow include:

  • Install the IBM Application Client for WebSphere Application Server. When deploying Java clients to workstations, you need to use the WebSphere client software to properly interact with a remote enterprise bean running in a WebSphere Application Server. We do it here to demonstrate the configuration.
  • Deploy a temperature converter EJB application in WebSphere Application Server using the J2EE™ Perspective in Application Developer, which includes a fully functional edition of WebSphere Application Server for testing your applications. Through Application Developer, you can communicate with a default WebSphere Application Server instance, bring up the administrative console and deploy the application (you will not need to import the Enterprise Archive (EAR) file into your workspace for this demo). (We use Application Developer for convenience; if you are using a stand alone WebSphere Application Server, the steps are the same.)
  • Use the Eclipse Plug-in Development environment to build the RCP client. We will configure the Eclipse Plug-in Launcher to interact with the WebSphere Application Server Java Thin Client, which is just the IBM JDK with server extensions needed to communicate with WebSphere Application Server. We chose this over the J2EE Application Client Container because it offers a simpler configuration.
  • Export the RCP application and run it as a standalone application. You need to understand how to configure your plug-in dependencies and JRE to work with the WebSphere Application Server thin client.

To follow this exercise, you will need:

  • Rational Application Developer V6 (or Eclipse 3)
  • WebSphere Application Server V6 (with slight modification, you can also use Eclipse 3 and WebSphere Application Server V5)
  • IBM Application Client for WebSphere Application Server (included with WebSphere Application Server V6)
  • The download file included with this article. The instructions assume the download file has been extracted into the root of C:\.

Set up J2EE application

The first thing we need to do is install the IBM Application Client for WebSphere Application Server, which is included with WebSphere Application Server V6 (if you do not have the client, you can change your configuration to point to the server JDK within the Application Developer test environment, or within an actual WebSphere Application Server installation), and then deploy the application to a running WebSphere Application Server:

  1. The J2EE application client is installed using the Installation wizard interface. After running the LaunchPad of your WebSphere install, select the IBM Client for IBM WebSphere Application Server.
  2. As we follow the wizard, we install into the C:\WebSphere6ND\AppClient directory. The Windows® batch (BAT) file included in the download ZIP file makes use of this class path; if you choose another directory, you will have to modify the BAT file to reference the new directory instead. Figure 1 shows the 3rd screen of the wizard where you select the directory.
    Figure 1. Installation wizard
    Installation wizard
  3. We also selected a typical installation, and entered localhost for the Hostname, as shown in Figure 2.
    Figure 2. Installation wizard
    Installation wizard
    Next we will use Application Developer to deploy the EAR to WebSphere Application Server. (This is purely for the convenience of building and testing the plug-in from the same workspace; You could also just deploy the application in a standalone WebSphere Application Server instance, with Eclipse configured to talk to it.
  4. Open Application Developer using the Start menu and go to a workspace such as C:\RCPEJBClient\workspace, (Figure 3).
    Figure 3. Workspace Launcher
    Workspace Launcher
  5. Close the default Welcome page (Figure 4).
    Figure 4. Rational SDP Welcome page
    Rational SDP Welcome page
  6. Switch to the J2EE Perspective if you do not find yourself there by default.
  7. Find the Servers view on the bottom frame and right click on WebSphere Application Server v6.0 (Figure 5). At this point, Application Developer will check if the default instance of WebSphere Application Server is running.
    Figure 5. Servers tab
    Servers tab
  8. The status should come back as "Stopped". Right-click on the server and select Start (Figure 6). (You can also start the server by going to <Application Developer_INSTALL_ROOT>/runtimes/profiles/default/bin and perform startserver server1).
    Figure 6. Start server
    Start server
  9. When the server is started, you can run the administrative console by right-clicking the server and selecting Run administrative console (or open a browser and go to http://localhost:9060/admin), as shown in Figure 7.
    Figure 7. Run admin console
    Run admin console
  10. Log in with any user id (Figure 8).
    Figure 8. Run admin console
    Run admin console
  11. Expand the Applications section and select Install New Application (Figure 9).
    Figure 9. Install new application
    Install new application
  12. Browse to C:\RCPEJBClient, select TemperatureEAR.ear and then Next (Figure 10). The TemeratureEAR application is a simple method that converts the temperature from Celsius to Fahrenheit (although probably not too accurately).
    Figure 10. Install new application
    Install new application
  13. On the Bindings page (Figure 11), leave the defaults and select Next.
    Figure 11. Install new application
    Install new application
  14. On the next page, Step 1 of the application installation process, select Deploy enterprise beans and then Step 7 Summary (Figure 12).
    Figure 12. Install new application
    Install new application
  15. On the Step 7 dialog, select Finish (Figure 13). The installation should take a minute or two (Figure 14).
    Figure 13. Install new application
    Install new application
    Figure 14. Install new application messages
    Install new application messages
  16. When the installation is finished, select Save to Master Configuration (Figure 15).
    Figure 15. Save to Master Configuration
    Save to Master Configuration
  17. On the Save dialog, select Save (Figure 16).
    Figure 16. Save to Master Configuration
    Save to Master Configuration
  18. Now, we will start the application. From the Applications menu, select Enterprise Applications (Figure 17).
    Figure 17. Enterprise applications
    Enterprise applications
  19. Select TemperatureEAR and then Start (Figure 18).
    Figure 18. Enterprise applications
    Enterprise applications
  20. The corresponding icon in the Status column should indicate that the application has been started (Figure 19).
    Figure 19. Enterprise applications
    Enterprise applications
  21. Logout of the admin console (Figure 20).
    Figure 20. Logout of admin console
    Logout of admin console

Create RCP client

We are now ready to create the RCP client application, which we will do as a simple plug-in using the Plug-in wizard. When creating RCP applications, you should usually create several plug-ins with reusability in mind. For example, you could rewrite this example to create a single plug-in with your J2EE dependencies, another one for the View components, and one for the RCP Shell. This enables different plug-ins to reuse, for example, the J2EE code. However, we will only have one plug-in for this exercise, primarily to limit the scope of this article.

Create a plug-in project

  1. To create a Plug-in project in Application Developer, select File => New => Other from the J2EE Perspective (Figure 21).
    Figure 21. Create a new plug-in project
    Create a new plug-in project
  2. In the New Project wizard, make sure that Show All Wizards is selected. Expand Plug-in Development and select Plug-in Project (Figure 22).
    Figure 22. New Project wizard
    New Project wizard
  3. At this point, you may get a prompt to enable the plug-ins for plug-in development (Figure 23). If so, select OK.
    Figure 23. Confirm plug-in enablement
    Confirm plug-in enablement
  4. In the Create a new plug-in project dialog (Figure 24), name the project: com.ibm.issw.temperature.form. This is a common naming convention for plug-ins. Make sure you select the options shown in Figure 24:
    • Your plug-in project will also be a Java project since you will be adding Java code.
    • In Eclipse 3.0, you have the option of setting up your run time dependencies using a manifest file, which we opt to use.
    Select Next.
    Figure 24. Create a new plug-in project
    Create a new plug-in project
  5. One the next dialog, populate the plug-in data as shown in Figure 25, then select Next.
    Figure 25. Create a new plug-in project
    Create a new plug-in project
  6. We will use a template to build the plug-in. Since we will be building a plug-in with a view, select Plug-in with a view, then Next (Figure 26).
    Figure 26. Create a new plug-in project
    Create a new plug-in project
  7. On the next dialog, we will define information about the View class. Enter the information exactly as shown in Figure 27, then Next.
    Figure 27. Set view settings
    Set view settings
  8. Finally, on the View Features dialog (Figure 28), deselect all the features. (We will import our own view class.) Select Finish.
    Figure 28. Set view settings
    Set view settings
  9. When asked to switch to the Plug-in Development Perspective (Figure 29), select Yes.
    Figure 29. Confirm Perspective switch
    Confirm Perspective switch

Import J2EE JAR and EJB client JAR

We will now import two JARs into our new plug-in:

  • j2ee.jar -- The plug-in interacts with the EJB client API, and so you need j2ee.jar in your classpath.
  • EJB client JAR -- Contains the needed client interfaces and generated proxy and stubs to properly connect to running enterprise beans.
  1. In Application Developer, right-click on the plug-in project and select Import (Figure 30).
    Figure 30. Import JARs
    Import JARs
  2. Select File System, then Next (Figure 31).
    Figure 31. Import JARs
    Import JARs
  3. There are several places you can get j2ee.jar. Since the RCP will be using the IBM Application Client for WebSphere Application Server at run time, it is best to use that JAR, which you can find in <WAS_CLIENT_INSTALL_ROOT>/lib, as shown in Figure 32. Make sure that j2ee.jar is the only one selected. (If your plug-in uses any other WebSphere APIs, such as a WebSphere programming model extension, you would need to import those also. Otherwise, you do not need to import other WebSphere run time JARs; at run time, the generated EJB proxy code and client container code load the classes from the WebSphere thin client classloader.) If you have not installed the client software, you can get j2ee.jar from <Application Developer_INSTALL_ROOT>/runtimes/base_v6/lib or <WAS_ROOT>/lib.
    Figure 32. Import JARs
    Import JARs
  4. Next, we need to import the EJB client JAR, which is a special JAR file with the code needed to call an EJB from a remote location. This includes the EJB client interfaces and generated RMI/IIOP code. (If you were building your own EJB application, you could generate the client JAR through Application Developer by right-clicking your EJB Project and selecting Create EJB Client Jar) For this exercise, the EJB client JAR is provided in the download file. Import the JAR file using the File System option, as before, go to C:\RCPEJBClient, and select TemperatureEJBClient.jar. (Figure 33)
    Figure 33. Import JARs
    Import JARs
  5. Our plug-in project should now have two JAR files, as shown in Figure 34.
    Figure 34. Imported JARs
    Imported JARs
  6. We now need to setup the compile time classpath for builds and compilation in the workspace. This will enable the plug-in code to compile successfully both inside the Eclipse IDE and in an automated build. Build time classpath information is updated in the Build Section of the plug-in configuration editor. Select the Build tab, shown in Figure 35.
    Figure 35. Build section
    Build section
  7. Locate the Binary Build section (Figure 36) and select the two JAR files as shown. If you choose to do a binary build of a plug-in, the JARs need to be included in the Build. The Binary build allows you to just build your binary and then use a downloadable Eclipse RCP binary. For this exercise, we will manually copy the plug-ins to run the Eclipse RCP application.
    Figure 36. Binary Build section
    Binary Build section
  8. For the code to compile successfully, you need to add the JARs to the compile time classpath. You can do this by adding the JARs in the Extra Classpath Entries on the bottom of the Build section (Figure 37). This will update the Project Build Path in Eclipse.
    Figure 37. Extra Classpath Entries
    Extra Classpath Entries
  9. The changes made on the Build page update the build.properties file. You can view this file by selecting the build.properties tab.
  10. For your plug-in code to find the J2EE and EJB client code at run time, it needs to be added to the run time classpath of the plug-in. This can be done through the plug-in configuration editor, which should have opened by default. (If not, double-click plug-in.xml to open it.) Select the Runtime tab, and in the Run-time libraries section, select the Add button (Figure 37) and add the two JARs you just imported.
    Figure 38. Add run time libraries
    Add run time libraries

The Runtime dialog updates the MANIFEST.MF file of the plug-in. Much like J2EE applications, the manifest defines the run time classpath. You can see the manifest by going to the MANIFEST.MF tab.

Build the view using SWT form widgets

We will now build the view. The View class is provided in the download file. We will import the class (overriding the one generated for us by the View template) and then examine the relevant portions of the code. Before starting, we need to specify the plug-ins that our plug-in depends on. We will be using Standard Widget Toolkit (SWT) form widgets on our view, so we need to set up the dependencies on the Eclipse plug-in that contains the form widgets.

  1. Select the Dependencies tab and select Add (Figure 39). Locate the org.eclispe.ui.forms plug-in.
    Figure 39. Dependencies
    Dependencies
  2. Import the View class provided in the download file, overriding the one that was generated. Under the src folder, right-click on the com.ibm.issw.temperature.form.views package, and select Import (Figure 40).
    Figure 40.
    Import views
  3. Select File System and then Next. Browse to the C:\RCPEJBClient\View directory, and import the three files into the package, as shown in Figure 41.
    Figure 41. Import file system resources
    Import file system resources
  4. You should get a warning that you are going to override the existing class. Select Yes To All (Figure 42).
    Figure 42. Override class warning
    Override class warning
  5. Open the imported TemperatureView.java (Figure 43).
    Figure 43. Open imported view
    Open imported view
  6. We will focus on two methods (Figure 44):
    • createPartControl(Composite) -- used to build up your view from various SWT widgets.
    • handleEvent() -- in the inner class, provides the logic that is invoked when pressing the command button SWT widget.
    Figure 44. Main methods
    Main methods
  7. The createPartContol() method is shown in Listing 1. The code uses the FormToolkit class to help build controls on the parent component; in this case, the view. The required labels, button, and text box are created, and a listener is assigned to the button. The listener is an inner class of the View.

    Listing 1

    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);
    }
  8. The event handling method of the inner class is shown in Listing 2. In this class, the value in the text box is read and the EJB is called using the EJB client API. The code looks up the EJB home and gets the remote interface. It then calls the method and populates the result label with the resulting value. (Keep in mind it is best to hide the EJB call behind a business delegate rather than calling it directly in the plug-in code. For the purpose of this article, we have simplified the code. Calling EJBs directly from view classes is generally not a recommended practice.)

    Listing 2.

    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());
    	}
    
    }
  9. You may have noticed that a property file is used to avoid hard coding the EJB JNDI name and location of the application server. When deploying the RCP application, you can change the properties file to point to an actual remote EJB location.

    Listing 3

    TemperatureView.JNDIName=ejb/TempConverter
    TemperatureView.Title=Celsius to Fahrenheit Temperature Converter
    TemperatureView.Button=Convert to Fahrenheit
  10. When building a plug-in, you usually need to add the plug-in to your plug-in.xml file and choose the extension point (in this case, you are extending the View plug-in). This was added for us, since we used the View template in the wizard. You can see this in the Extensions tab or you can view the source of the plug-in.xml The extension configuration is shown in Listing 4.

    Listing 4

    <extension
    	point="org.eclipse.ui.views">
          <category
                name="Temperature Category"
                id="com.ibm.issw.temperature.form">
          </category>
          <view
                name="Temperature View"
                icon="icons/sample.gif"
                category="com.ibm.issw.temperature.form"
                class="com.ibm.issw.temperature.form.views.TemperatureView"
                id="com.ibm.issw.temperature.form.views.TemperatureView">
          </view>
    </extension>

Create your own RCP workbench and perspective

Because we are developing an RCP application, using the default Eclipse workbench, which is tailored as an IDE, is not ideal. Therefore, we will build our own workbench and perspective instead. We will import the classes, which are provided in the download file, into our plug-in, then add entries into the plug-in.xml for the default workbench and perspective.

  1. Right-click on the src folder and select Import (Figure 45).
    Figure 45. Import classes
    Import classes
  2. Select File system, then Next. Browse to the C:\RCPEJBClient\RCPCode\src folder and import the three classes, as shown in Figure 46.
    Figure 46. Import classes
    Import classes
  3. The classes are imported to the (default package), which is the root (Figure 47).
    Figure 47. Import classes
    Import classes
  4. Let's examine the classes:
    • RcpWorkbenchAdvisor -- used to create our workbench. The code sets certain configurations, such as the size and title, and also disables certain default items.

      Listing 5

      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");
      
          }
      
      }
    • MyRCPPerspective -- the view is added to the perspective. This is the initial layout of the perspective. The code also disables the editor area since we are not building a plug-in to edit files.

      Listing 6

      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);
      	}
      
      }
    • platform -- the main class of the RCP application. The workbench is created and the RCP application is launched.

      Listing 7

      Click to see code listing

      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();
      		}
      	}
      
      }
  5. With the code now added, we need to add it to our plug-in.xml. Select the Extension tab, and then Add (Figure 48).
    Figure 48. Add extensions
    Add extensions
  6. Since we are writing an application, we need to extend the org.eclipse.core.runtime.applications (Figure 49).
    Figure 49. Add extensions
    Add extensions
  7. Select Finish.
  8. In the Extension Details dialog, add RcpApplication as the Id (Figure 50).
    Figure 50. Add extensions
    Add extensions
  9. Right-click the extension point and select New => application (Figure 51).
    Figure 51.
    Add extensions
  10. Right-click (application) then select New => run (Figure 52).
    Figure 52. Add extensions
    Add extensions
  11. In the Extension Element Details dialog, browse for the TempRCPApplication class (Figure 53).
    Figure 53. Extension Element Details
    Extension Element Details
  12. To add the perspective, add another extension and select the org.eclipse.ui.perspectives extension point (Figure 54).
    Figure 54. Extension Point Selection
    Extension Point Selection
  13. Right-click the point and select New => perspective (Figure 55).
    Figure 55. Add extensions
    Add extensions
  14. In the Extension Element Details, browse to the perspective class as shown in Figure 56):
    Figure 56. Extension Element Details
    Extension Element Details
  15. Update the ID to match the class name (Figure 57):
    Figure 57. Extension Element Details
    Extension Element Details
  16. The extensions should now appear as they do in Figure 58. Save the plug-in configuration changes by selecting either File => Save or Ctrl-S.
    Figure 58. Add extensions
    Add extensions

Alternatively, you can add the plug-in by hand by adding it directly to the plug-in.xml file, shown in Listing 8. The added code is shown in bold type:

Listing 8

<plug-in>

   <extension
         point="org.eclipse.ui.views">
      <category
            name="Temperature Category"
            id="com.ibm.issw.temperature.form">
      </category>
      <view
            name="Temperature View"
            icon="icons/sample.gif"
            category="com.ibm.issw.temperature.form"
            class="com.ibm.issw.temperature.form.views.TemperatureView"
            id="com.ibm.issw.temperature.form.views.TemperatureView">
      </view>
   </extension>
   <extension
         point="org.eclipse.core.runtime.applications">
      <application>
         <run class="TempRCPApplication"/>
      </application>
   </extension>
   <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            class="MyRCPPerspective"
            name="com.ibm.issw.temperature.form.perspective1"
            id="MyRCPPerspective"/>
   </extension>

</plug-in>

Test your RCP EJB client

We are now ready to run the RCP EJB client. We will first unit test our RCP application from within Application Developer. We will then export our plug-in and set it up to run outside the development environment.

Testing inside Application Developer

With Eclipse 3.0, you can create launch configurations for running plug-ins. These launch configurations need to be set up to use the WebSphere V6 JRE (which includes the IBM Application Client for WebSphere Application Server and WebSphere Application Server), which is added through the Perspective Preferences. However, rather than using Eclipse, we will be using Application Developer, where the JRE is already installed.

  1. From the Application Developer Main Menu, select Run =>Run.... (Figure 59).
    Figure 59. Create launch configuration
    Create launch configuration
  2. In the Launch Configuration wizard, select Run-time workbench and New (Figure 60).
    Figure 60. Create launch configuration
    Create launch configuration
  3. Name the configuration MyRCPClient. In the Program to Run section, select your plug-in, com.ibm.issw.temperature.form.RcpApplication, for Run an application, and WebSphere v6 JRE for JRE (Figure 61).
    Figure 61. Create launch configuration
    Create launch configuration
  4. For VM arguments, enter the code shown in Figure 61 by pasting the code provided in C:\RCPEJBClient\Snippet1.txt (Listing 9). Do not run yet. The VM arguments point to the directory where the IBM Application Client for WebSphere Application Server is installed. If you installed it in a different directory, use that directory. Otherwise, use the WebSphere instance in Application Developer located at <Application Developer_INSTALL_ROOT>/runtimes/base_v6.

    Listing 9

    -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
  5. On the Plug-in tab, we need to include which plug-ins our our new plug-in depends on. We can easily do this by following the click sequence shown in Figure 62.
    Figure 62. Plug-in dependencies
    Plug-in dependencies
  6. Select Apply, then Run. The client should look like Figure 63.
    Figure 63. Running client
    Running client
  7. Enter a value, then select Convert to Farenheit.
  8. The result should display, similar to Figure 64. (The first invocation will take longer than subsequent ones, because it needs to establish initial communication with WebSphere Application Server.)
    Figure 64. Client results
    Client results

Building and running RCP application outside Application Developer

To run the RCP application outside of Application Developer, we will need to use the Export plug-in wizard. In Eclipse 3, there is no export mechanism for RCP applications, but you could use a binary build to accomplish this process. For educational purposes, we will manually deploy it.

  1. Right click on the plug-in project and select Export (Figure 65).
    Figure 65. Export plug-in project
    Export plug-in project
  2. In the Export dialog (Figure 66), select deployable plug-ins and fragments, then Next.
    Figure 66. Export plug-in project
    Export plug-in project
  3. From the Deployable plug-ins and fragments dialog, select our plug-in, select to deploy it as a directory structure, then deploy it to the directory as shown in Figure 67. Select Finish.
    Figure 67. Export plug-in project
    Export plug-in project
  4. The PDE Export wizard (Figure 69) will run.
    Figure 68. PDE Export wizard
    PDE Export wizard
  5. We need a BAT file to launch our application. For simplicity, one is provided one in the download file. Copy the BAT file from C:\RCPEJBClient\MyRCPApp.bat into the directory where you exported your plug-in.
  6. The BAT file will use the application client JRE (assuming the IBM Client for WebSphere Application Server is in C:\WebSphere6ND\AppClient; if not, update the script to replace the directory by updating the variable at the beginning to point to the application client, or to WebSphere Application Server if you are not using the client.).

    (We are testing our RCP application with WebSphere Application Server Base. If, in production, you will be invoking an EJB application deployed to a cluster, the argument Djava.naming.provider.url=corbaloc::localhost should have a URL that represents a cluster such as: corbaloc::<host1>:<port>,:<host2>:<port>.)

    Listing 10

    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
  7. Since we are manually exported the plug-in, we need to copy the startup.jar and the base plug-ins from our Eclipse install. In Application Developer, the base Eclipse is located under the eclipse directory under the Application Developer install (Figure 69).
    Figure 69. Copy startup.jar
    Copy startup.jar
  8. Paste startup.jar into the directory where plug-in was deployed.
    Figure 70. Paste startup.jar
    Paste startup.jar
  9. Next, copy the required plug-ins:
    • 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
    Remember that you can automate this process using binary build or scripted ANT builds.
    Figure 71. Copy required plug-ins
    Copy required plug-ins
  10. Run the application by executing MyRCPApp.bat. (Again, the initial request will take longer that subsequent ones.)
    Figure 72. Run client
    Run client

Conclusion

This article described how to build EJB client applications using the Eclipse Rich Client Platform (RCP). The Eclipse platform contains a wealth of widgets, views, frameworks (such as the Eclipse Modeling Framework), and other extensions that can be used to build powerful client applications. Understanding how to integrate Eclipse RCP applications with WebSphere Application Server is essential to building integrated client applications.


Acknowledgement

The authors wish to thank Wayne Beaton for reviewing and improving this article.


Download

DescriptionNameSize
Sample Rich Client Platform applicationRCPEJBClient.zip  ( HTTP | FTP )1.6 MB

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=33368
ArticleTitle=IBM WebSphere Developer Technical Journal: Creating EJB clients using the Eclipse Rich Client Platform and Rational Application Developer V6
publish-date=01262005