Deploying EJBs to BEA Weblogic Server

You can use the EJB Deployment Expert to compile your EJBs and deploy them on BEA WebLogic Server (WebLogic):

This section describes how to set up your Together project and your environment so that you can use Together to compile both EJB clients and deploy your EJBs to the server. At the end, there is a short tutorial using a simple sample project.

Setting project properties and environment

If your EJB project contains one or more EJB clients that you want to compile and run from Together, you need to specify several paths and archives in the Search/Classpaths page of the Project Properties dialog before compiling the client(s). For Weblogic server, the order of the specifications is important, so follow the instructions below when setting up your EJB project to deploy to BEA Weblogic server.

If your project does not contain any EJB clients, you can skip the next sections.

Search/Classpath specifications

If you want to compile/run EJB clients in the same project as EJBs, you need the following specified in the Search/Classpath tab of the Project Properties dialog In addition to other standard and other libraries needed for your EJBs and/or clients :

%WL_HOME%\lib\weblogicaux.jar *
%WL_HOME%\classes
%J2EE_HOME%\lib\j2ee.jar

Where: %WL_HOME% is the home directory of Weblogic Server (e.g. e:\weblogic), and %J2EE_HOME% is the home directory of Java2 Enterprise Edition (e.g. c:\j2sdkee1.2)

* IMPORTANT: weblogicaux.jar should always be first in the list, ahead of even standard libraries.

To edit Search/Classpath:

  1. On the Main menu choose File | Project Properties to display the Project Properties dialog.

  2. Click the Advanced button to display the Resources group box.

  3. Click the Search/Classpath tab.

  4. Click the Add Path button to add paths (e.g. %WL_HOME%\classes), or the Add Zip/JAR button to add an archive (e.g. %J2EE_HOME%\lib\j2ee.jar).

Note: Together 4.0 users may need to remove and then re-add resources in order to get the file weblogicaux.jar first in the Search/Classpath list. The order will be editable in future releases.

Environment path

You should add the path %J2EE_HOME%\nativelib in the PATH environment variable on Windows systems. (This path finds ioser12.dll).

Deploying sample EJB to WebLogic server

This section shows you step-by-step how to compile an EJB, deploy it to the server, compile an EJB client in the same project, and run it against the the deployed EJB.

System requirements

The example is based on BEA Weblogic Server version 5.1. It uses a simple example project Hello World which is located in $TOGETHER_HOME$/samples/java/ejb/WeblogicServer. To try the steps you need the following:

Compiling and deploying the sample EJB

IMPORTANT: When deploying EJBs, make sure your WebLogic server does not already have a deployed EJB with the same name as the one you are deploying (see Verifying deployment below). If it does, you must either restart Weblogic server after each deployment, or give your EJB a different name.

  1. Open the HelloWorld.tpr project from $TOGETHER_HOME$/samples/java/ejb/WeblogicServer/HelloWorld/ (File | Open Project).

  2. Open the hello diagram. You should see the HelloBean class. Open the Message pane so you can monitor process messages.

  3. Check that you have the correct port number and password for Weblogic server available.

  4. Launch the EJB Deployment Expert (Tools menu). Weblogic Application Server 5.1 is the default target server.

  5. Make sure that all available check boxes are checked (including Hot Deploy).

  6. Even though it's the default, open the drop-down list and select Weblogic Application Server 5.1 in the list to display server startup options.

  7. In the server startup options, check Start Weblogic Server 5.1.0 (normal mode) and uncheck Start Weblogic Server 5.1.0 (debug mode).

  8. Press Next button.

  9. Specify the paths to:

  10. Press Next button.

  11. Specify the server host name (e.g. localhost), system password, and port number. Press Finish button.

Together does a number of things now:

Verifying deployment

Assuming you checked Hot Deploy in the EJB Deployment Expert, the last message lines in the Message pane should be:

//WLS51: Connecting to localhost, port 7001...Successfully connected.//
//WLS51: Done deploying HelloWorld with c:\temp\DEPLOYABLE_HelloWorld.jar//.
//WLS51: Finished with 0 errors, 0 Warnings.//

Host name and port number values will match those you specified in the expert.

To be sure the generated JAR file was successfully deployed to the WebLogic server, you can run the Weblogic Console. In the console window, check for:

EJB Home interface: 'hello.HelloHome' deployed bound to the JNDI name: 'hello.HelloHome'.

This verifies that the bean is deployed.

Troubleshooting tips


Compiling and running the example client

To test the deployed EJB you need an EJB client to access it. The HelloWorld example contains a client class that you can compile and run to test your deployed sample EJB.

  1. In the Project Properties dialog, check that the Search/Classpath specifications are as described in Search/Classpath specifications above. (File | Project Properties - Advanced)

  2. Open the HelloWorld.client.weblogic package in the Explorer and open the weblogic class diagram containing the HelloClient class.

  3. Right-click on the client class and select Tools | Compile from the speedmenu.

  4. When compilation is complete the Message pane displays a message that the tool is completed.

  5. Select the HelloClient class, right-click on it and choose Tools | Run from the speedmenu.

Your deployed EJB runs and outputs the string "Hello World". Together picks up this output and displays it as a message line in the message pane. The output also appears in the server console.

Debugging the example bean and client

This section contains an exercise you can follow to learn how to debug bean and client from within the Together environment.

  1. Close the running Weblogic Server.

  2. For debugging your bean you must restart the server in a debug mode. To do this:

  3. Read instructions in 'EJB Deployment' message window and follow them.

  4. On the main menu choose Tools | Debugger | Attach to remote process.

  5. In the subsequent dialog set the following values, then click OK:

  6. Deploy 'HelloBean' to WebLogic Server as previously described.

  7. Select the hello() method of the 'HelloBean' class in the diagram. In the Editor, set a breakpoint on the first string in it (F5 or speedmenu | Toggle breakpoint).

  8. Compile the HelloClient class as previously described (speedmenu - Compile).

  9. In the Editor, set a breakpoint on the first string after the try statement in the s method.

  10. On the Main menu choose Tools | Debugger | Debug project. The process will stop on the break point in the 'HelloClient' class.

  11. Now you can use speed buttons to manage your process (Restart/Resume program, Reset program,step over, step in, etc.). They are situated in the Debugger page of the process. Or you can use hot keys (Step over - 'F8', Step in - 'F7') When you pass line calling the hello() method, the debugger will stop on the breakpoint in the 'HelloBean' class.

  12. When you have traced all the hello() method, click the measure Program speed button on the remote process page to continue running WebLogic. As a result you'll be stopped in the 'HelloClient' class after the point at which the hello() method of the bean was invoked.

  13. Continue step by step debugging, or click the Resume Program button to finish the debugging process.

Deploying from an EJB Assembly diagram

In the previous sections, you have deployed a bean described in a Class diagram. This technique is fine for prototyping, but in real scenarios you want to specify such things as container transaction attributes on classes and methods, security roles, and method permissions. The EJB Assembly diagram enables you to do this, and so you can run the deployment expert against this type of diagram as well. For more information on this type of diagram and how to work with it, see User's Guide: EJB Assembly diagrams.

In this section you can do an exercise that uses an EJB Assembler diagram for deploying your Enterprise JavaBeans.

  1. Close the running WebLogic Server.

  2. In the example HelloWorld project, open the AssemblyDiagram diagram. You will see a shortcut to the hello.HelloBean class, and two ContainerTransaction elements, one with transaction attribute displaying as Supported and one as NotSupported. These elements are linked to the bean class and the hello() method respectively.

  3. Start the EJB Deployment Expert again (Tools | EJB Deployment Expert) and deploy your EJB. For more information about deployment process refer to section Deploying the Bean of this guide.