Skip to main content

Using WebSphere Studio with external EAR applications

Paul Pacholski (pacholsk@ca.ibm.com), Technical Sales Consultant, IBM
Photo of Paul Pacholski
Paul Pacholski is a technical sales consultant supporting WebSphere development tools and specializing in Web services and WebSphere Business Integration products. You can reach Paul at pacholsk@ca.ibm.com.
Elson Yuen (eyuen@ca.ibm.com), software developer, IBM Toronto Lab, IBM
Photo of Elson Yuen
Elson Yuen is a software developer in the IBM Toronto Lab working on WebSphere Studio Application Developer. He is currently designing and developing the server tooling, including the WebSphere Test Environment. Previously, he was the key developer on the VisualAge® for Java™ WebSphere Test Environment JSP debugging support and the WebSphere Test Environment Control Centre. Elson has a Bachelors degree in Electrical Engineering with Management Science options from the University of Waterloo, Ontario. You can contact Elson at eyuen@ca.ibm.com..

Summary:  This article describes a simple and elegant technique for reusing code in external EAR applications within WebSphere Studio Application Developer. Rather than importing large EAR applications into the Application Developer workspace, it is more efficient to keep them outside and reference them. This article shows you how, and covers development and testing considerations, including compiling code that references external EAR applications and running them in the WebSphere Test Environment.

Date:  01 Mar 2004
Level:  Advanced
Activity:  139 views

Introduction

If you are a C++ programmer, do you remember how C++ frameworks and class libraries were packaged and distributed? They were compiled as DLLs (dynamic link libraries). To distribute a class library, you would simply provide the DLL and the C++ include files. To call a method from a framework in a DLL, all you needed to do is to compile your C++ code with the framework's include files. Simple and easy!

How does a J2EE application developer, using IBM ® WebSphere® Studio Application Developer, build and test J2EE applications that reuse code in an external EAR applications?

This article describes an simple and elegant technique for reusing code in external EAR applications with WebSphere Studio Application Developer (hereafter called Application Developer). Rather that importing several large EAR applications into the Application Developer workspace it is more efficient, from the point of view of resource use, to keep them outside and reference them. This article shows you how to do that, and covers development and testing considerations, including compiling code that references external EAR applications and running them in the WebSphere Test Environment. Although external EAR applications and the technique described in this article and are not formally supported by WebSphere Studio, they will be useful to users who are interested in exploring the flexibility of the product.

The external EAR application technique is described in five easy steps:

  1. Create and configure WebSphere Application Server V5.0.
  2. Add external EAR file to WebSphere Application Server.
  3. Expand the external EAR file.
  4. Compile the earProj2 EAR application.
  5. Test the Web and EJB modules in the external EAR application.

The procedures in this article require the use of WebSphere Studio Application Developer for Windows, V5.0.1 or V5.1, but no familiarity with the basic operations of Application Developer is required.


The external EAR application test scenario

The test scenario in this article uses two EAR applications: earProj1 and earProj2. earProj2 is loaded into Application Developer, and earProj1 resides outside of Application Developer, but is loaded by the WebSphere Test Environment to test the earProj2 application in Application Developer. earProj2 contains one session EJB called TestBeanTester. earProj1 EAR contains a single session EJB called TestBean:

The testTestBean() method makes a call (via a remote interface) to the hello() method in the external EAR application. To demonstrate that a method call can be made to an external EAR, we will launch the TestBeanTester EJB in the WebSphere Universal Test Client.

The earProj1 EAR application also contains a Web application with a single index.jsp file. To show that we can launch a Web application from an external EAR, we will launch the index.jsp file in the WebSphere Test Environment.


Step 1. Create and configure WebSphere Application Server V5.0

  1. Create WebSphere Application Server V5.0 server and server configuration:
    1. Start Application Developer and switch to the Server perspective.
    2. From the main toolbar, click on the Create server and server configuration button Create server and                                 server configuration button .
    3. On the "Create a new server and server configuration page," enter WAS5 for server name and WebSphere version 5.0 => Test Environment for Server type:
    4. Click Finish.
  2. Configure WebSphere Application Server V5.0:
    1. Switch to the Servers view and double-click on the WAS5 server. The Server Configuration Editor opens:
    2. In the Server Configuration Editor, click the Configuration tab.
    3. In the Server Configuration section, check the Enable administration console checkbox, because we will be launching the WebSphere Administration Console.
    4. In the Server Settings section, select SINGLE for Application class loader policy, because we will be calling an EJB from another EAR application:
    5. Press Ctrl-S to save and close the Server Configuration Editor.
  3. Import the earProj2 EAR application and add it to the WAS5 server:
    1. From the main menu bar, select File => Import.
    2. On the Select page of the Import Wizard, select EAR file and click Next.
    3. On the Enterprise Application Import page, click Browse to navigate to the second EAR application (earProj2.ear) supplied with this article:
    4. Click Finish.
    5. In the Server Configuration view, right-click on WAS5 server and select Add and remove projects.
    6. On the Add and Remove Projects page of the Add and Remove Projects Wizard, select earProj2 and click Add>. This will add earProj2 to the Configure projects list:
    7. Click Finish. You will see compile errors in the Task view -- we will fix them later.

Step 2. Add external EAR to WebSphere Application Server

  1. Launch the WebSphere Administrative Console:
    1. From the Servers view, select WAS5 server and from the Servers toolbar, click the Start the server button Start the server button. This action will start the WebSphere Unit Test Environment.
    2. After you see message Server server1 open for e-business in the Console view, switch to the Servers view. Right-click on WAS5 server and select Run administrative console.
  2. Launch the WebSphere Administrative Console.
    1. In the Login window, for User ID, enter your user name and click OK.
    2. In the WebSphere Application Server Version 5 Administrative Console, from the left pane, select Applications => Install New Application:
    3. On the Preparing for the application installation page, select the Local path button.
    4. Click Browse to navigate to the first EAR application (earProj1.ear) supplied with this article:

      In the example above, we moved earProj1.ear to the F:\tem\EARs directory.

    5. Click Next .
    6. On the second Preparing for the application installation page, click Next.
    7. On the Step 1 page enter:
      Item Value
      Directory to Install applicationEnter an existing directory, for example F:\temp\MyInstalledApps.
      Use Binary Configuration

      enable

      Create MBeans for Resource disable
      Use Binary Configuration
      The application server will use the binding, extensions, and deployment descriptors in the application deployment document, the deployment.xml file (default), or the EAR file.
      Create MBeans for Resources
      We will not create MBeans for various resources (such as servlets or JSPs) within an application when the application is started. JMX MBeans represent the management interface for a particular piece of logic. All of the managed resources within the standard WebSphere Application Server infrastructure are represented as JMX MBeans.
    8. Click Next.
    9. On the Step 2 page, click Next.
    10. On the Step 3 page, click Next.
    11. On the Step 4 page, check the earProj1EJB and earProj1Web checkboxes:
    12. Click Next.
    13. On the Step 5 page, click Next.
    14. On the Step 6 page, click Finish.
    15. After you see a message similar to this:

      Click Save on the Administrative Console main toolbar:

    16. On the Save to Master Configuration pane, click Save:
    17. From the Servers view, select WAS5 and from the Servers toolbar click Stop the server Stop the server.

      If the external EAR application requires configuring data sources, JMS queues, and so on, use the Server Configuration Editor or the WebSphere Administrative Console.


Step 3. Expand the external EAR

In the previous step, we set the external EAR's install application directory to F:\temp\MyInstalledApps. In this section, we will be using the WebSphere EARExpader.bat file to expand earProj1.ear to that directory.

  1. Modify the EARExpander invoker file expand.bat:
    1. Using an editor of your choice, open the expand.bat file:
      1. Change E:\WSAD51 to your WebSphere Studio Application Developer V5.1 install directory.
      2. Change F:\temp\MyInstalledApps to the directory you specified above in step 2.2.7.
    2. Save the changes.
  2. Run the EARExpander invoker file expand.bat.
    1. Run expand.bat.
    2. Examine the expanded EAR application. When fully expanded, the directory you specified as the "Directory to Install Application" in step 2.2.7 should look similar to this:

Step 4. Compile the earProj2 EAR application

  1. Examine the compile errors:
    1. In the lower right pane of the Server perspective, click the Task tab:
    2. Examine the compile errors:

      These errors occur because the packages that define the TestBean remote interface and TestBeanHome classes are not included in the Application Developer workspace; they reside in the external EAR (earProj1).

    3. Click on the first error in the Task view to open the TestBeanTesterBean.java file and note the missing packages:
  2. Add earProj1EJB.jar to the build classpath:
    1. In the Navigator view, right-click on earProj2EJB and select Properties:
    2. In the Properties for earProj2EJB window, from the left pane, select Java™ build path.
    3. In the right pane, click the Libraries tab Libraries tab and then click Add External JARs.
    4. In the JAR Selection window, navigate to the directory where you expanded the ear1Proj.ear file in Step 3.2above (in this example, to the F:\temp\MyInstalledApps\ear1Proj.ear\ directory). Then select earProj1EJB.jar:
    5. Click Open.
    6. In the Properties for earProj2EJB window, click OK to add earProj1EJB.jar to the build classpath of the earProj2 EJB module. Application Developer rebuilt the EJB module. All compile errors have now been fixed, and the Tasks view shows no errors.

Step 5. Test the Web and the EJB modules in the external EAR application

  1. Update the server configuration:
    1. In Step 2 above, you installed the ear1Proj EAR application in the WebSphere Administrative Console. We will now update the Application Developer server configuration to reflect that change. Switch to the Server Configuration view and double-click on the WAS5 server:
    2. Click Yes on the WebSphere Server Warning message box: Warning message box.
    3. In the Server Configuration Editor, press ctrl-S to save changes and then close the Server Configuration Editor. In the Server Configuration view, the external EAR application earProj1 now appears:
  2. Run Web application in the external EAR:
    1. In the lower right pane of the Server perspective, click the Servers tab.
    2. Select the WAS5 server, and from the Servers toolbar, click the Run the server button Run the                                 server button . In the Console view, you should now see message indicating that the earProj1 was loaded successfully:
    3. From the main toolbar, click the Open Web Browser button Browser button.
    4. In the Web Browser window, enter http://localhost:9080/earProj1Web/index.jsp and press Enter. You should now see index.jsp from the Web application in the ear1Proj EAR application displayed in the Web Browser window:
  3. Invoke session EJB in the external EAR:
    1. Click on the J2EE Perspective button J2EE                             Perspective button in the top right corner to switch to the J2EE perspective.
    2. In the J2EE hierarchy view, select EJB Modules => earProj2EJB => Session Beans => TestBeanTester:
    3. Right-click and select Run on Server to start the WebSphere Universal Test Client.
    4. In the Server Selection window, click Finish.
    5. In the IBM Universal Test client Web application window, click TestBeanTesterLocal:

      then click TestBeanTesterLocalHome:

      and finally click TestBeanTesterLocal create():

    6. In the Parameters pane, click Invoke:

      and then click Work with Object:

    7. On the References pane, click String testTestBean(String):
    8. On the Parameters pane, enter Value from external EJB and click Invoke:
    9. Switch to the Console view. You should see a message from the Session EJB (TestBean) printed in the Console window:

Conclusion

This article showed you how to use an EAR application that is external to Application Developer. It addressed the compile considerations that arise when an EJB developed in an Application Developer workspace calls an EJB in an external EAR application. It also addressed testing considerations, and showed you how to configure the WebSphere Unit Test Environment server to load an external EAR application. Finally, it showed that, using the techniques described in this paper, you can invoke a Web application and an EJB from an external EAR application.

We have not shown how to access the contents of the WAR applications in an external EAR from the Application Developer workspace for WAR modules. We cannot simply point to the WAR file, since the classes are stored under an enclosed directory structure. We must expand the WAR file and point to the WEB-INF/classes directory in the expanded structure. Because both steps have already been discussed in Expand the external EAR above, you can use the contents of that directory to resolve the build classpath of the internal Application Developer projects.



Download

NameSizeDownload method
earProj.zip0.1 MBFTP|HTTP

Information about download methods


About the authors

Photo of Paul Pacholski

Paul Pacholski is a technical sales consultant supporting WebSphere development tools and specializing in Web services and WebSphere Business Integration products. You can reach Paul at pacholsk@ca.ibm.com.

Photo of Elson Yuen

Elson Yuen is a software developer in the IBM Toronto Lab working on WebSphere Studio Application Developer. He is currently designing and developing the server tooling, including the WebSphere Test Environment. Previously, he was the key developer on the VisualAge® for Java™ WebSphere Test Environment JSP debugging support and the WebSphere Test Environment Control Centre. Elson has a Bachelors degree in Electrical Engineering with Management Science options from the University of Waterloo, Ontario. You can contact Elson at eyuen@ca.ibm.com..

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=14476
ArticleTitle=Using WebSphere Studio with external EAR applications
publish-date=03012004
author1-email=pacholsk@ca.ibm.com
author1-email-cc=
author2-email=eyuen@ca.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers