Professional Documents
Culture Documents
Jbuilder Ejb Bea
Jbuilder Ejb Bea
development using
Borland JBuilder X ® ®
June 2004
1
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Contents
Introduction ......................................................................... 4
2
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Local debugging.................................................................................................................. 32
Remote debugging .............................................................................................................. 32
Set up and run remote WebLogic Server........................................................................................ 33
Create runtime configuration for remote debugging....................................................................... 34
Attach JBuilder to WebLogic Server remotely............................................................................... 35
Run the Struts client to debug the EJBs.......................................................................................... 36
3
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Introduction
Borland® JBuilder X Enterprise is a comprehensive set of award-winning visual development
tools for creating enterprise-scale applications written entirely in the Java™ programming
language for the Java™ 2 platform.
The audiences for this paper are project managers, architects, and developers. To fully
understand the contents of this paper, the reader should have basic knowledge of Java and
Enterprise JavaBeans.™
This paper provides an overview of creating, testing, debugging, optimizing, and deploying
EJB using Borland JBuilder X Enterprise and BEA WebLogic Server 8.1. The step-by-step
instructions demonstrate how easily a new-to-J2EE developer can build enterprise
applications using JBuilder X.
It will take approximately 1-2 hours for a developer to complete the steps illustrated in this
paper to be familiar with JBuilder X as well as build basic enterprise applications. The paper
focuses on building simple end-to-end EJB applications to help give developers a jumpstart
with JBuilder X and WebLogic Server 8.1. Through more complex Java applications can be
developed using JBuilder, this paper avoids such complexity.
Also install the latest updates for JBuilder X from the above link.
http://commerce.bea.com/showproduct.jsp?family=WLS&major=8.1&minor=2
4
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
This white paper uses C:\Borland\JavaStudio as the installation directory of JBuilder and
C:\ThirdParty\bea\weblogic81 as the installation directory for WebLogic Server 8.1.
1. Start JBuilder.
4. Click the Home Directory ellipses and navigate to the WebLogic Server directory
(C:/ThirdParty/bea/weblogic81/server). The Main Class and VM Parameters fields in
the Configure Servers window are populated automatically. See Figure 1 for details.
5
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
8. Provide Username and Password. They must be the same username and password
that you provided while creating the domain.
6
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Note: You may get an “Invalid JDK Installation directory” error when you click OK from the
Configure Servers window. That is because WebLogic may have shipped with a version of JDK
different from what is defined in JBuilder. Click the ellipses and choose the correctly installed JDK
(For example, we have chosen C:/ThirdParty/bea/jdk141_05). This configuration is a one-time
effort. From this point, the developers can use JBuilder X to build and manage enterprise
application for WebLogic without having to worry about configuration.
Create a project
2. In the Project Wizard, enter the Project Name as WebLogicSesProject and the
Directory Name as C:/Projects/weblogic81/WebLogicSesProject.
7
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Note: You can set WebLogic as the target application server in JBuilder Default Project Properties
so that the WebLogic application server is automatically selected for every project you create in
JBuilder. Click Project | Default Project Properties | select Server as WebLogic Platform Server
8.x to make WebLogic the default application server for JBuilder.
Figure 3: Selecting WebLogic Server 8.1 as the application server for the current project
From the JBuilder menubar, click File | New. In the Object Gallery, click EJB on the left tree
node. Click the EJB Designer icon on the right. Click OK. See Figure 4 for details.
8
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
1. In the EJB Designer Wizard, click New to create a new EJB Module.
2. In the EJB Module Wizard, Step 1 of 2, leave the defaults. Click Next.
Figure 5: Using the EJB Module Wizard to create an EJB Module in JBuilder
9
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Note: An EJB Module is merely a hosting environment for EJBs. Each EJB module produces an
EJB jar file. So if you like to keep different EJBs in different jar files, create one EJB Module for
each jar file.
3. Click Create EJB. Click Session Bean. See Figure 6 for details.
4. Enter the Bean name as WebLogicSes in the Session Bean Properties window, then
click anywhere in the designer to create the Session Bean.
10
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Note: The previous step automatically creates three EJB files (WebLogicSesBean.java,
WebLogicSes.java, and WebLogicSesHome.java). You can see these files in the JBuilder project
tree.
6. Click Add.
8. Enter the method name as getMessage(), return type as String and interfaces as
remote.
9. Right-click the EJB WebLogicSes and click View Bean Source. This opens the
WebLogicSesBean.java file in the JBuilder editor pane.
11
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
1. From the JBuilder main menubar, click Run | Configurations. The Project
Properties window appears with the Run tab selected. Click New to create a new
runtime configuration.
12
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
3. Click OK. Now you can see a runtime configuration called WebLogic Server in the
Runtime Configurations window.
Note: With the make operation, JBuilder creates WebLogic specific deployment descriptors
(weblogic.xml). Also JBuilder packages the EJB files and Deployment Descriptors and creates a jar
file named WebLogicSesMod.jar
13
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
14
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
JBuilder starts another tab in the message window showing the deployment status. See Figure
11 for details.
15
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
This exercise explains how to test the session bean using a Java client. JBuilder provides a
wizard to create a test client to test the EJBs.
Figure 12: Creating a test client to test a session bean using the JBuilder Wizard
5. In the EJB Test Client Wizard–Step 1 of 3, leave the default selection and click
Next.
6. In the EJB Test Client Wizard–Step 2 of 3, leave the default selection and click
Next.
7. In the EJB Test Client Wizard–Step 3 of 3, leave the default selection and click
Finish.
16
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
}
}
The test client runs within JBuilder by creating another tab in the message pane. You can see
the successful execution of the test client from the last line Message From the Test Client
“Hello There!! I am WebLogic Session Bean”.
Note: This message comes from the WebLogicSes EJB. The test client
WebLogicSesTestClient1.java has a wrapper method called getMessage(), which is responsible for
displaying the output of getMessage() business method of WebLogicSes into system output
console.
17
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Figure 13: Test client running within JBuilder and showing outputs from the EJB method
getMessage()
JBuilder X has the capabilities to optimize Java application. There are three optimization
capabilities as described below.
Optimizeit™ Profiler
Optimizeit Profiler enables developers to maximize application speed and reliability and to
quickly isolate critical code that requires performance improvements.
18
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
For this case, let’s attach Optimizeit memory Profiler with WebLogic Server 8.1. Click the
Optimize Project icon from the JBuilder toolbar and click WebLogic Server, as shown in
Figure 14.
The Edit Runtime Configuration window pops up and allows users to select one of the three
tools (Profiler, Thread Debugger, and Code Coverage). Select Profiler from Type combo
box. See Figure 15 for details.
Figure 15: The runtime configuration window allows you to choose an Optimizeit tool
19
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Click OK. Optimizeit starts within the JBuilder message pane. JBuilder has started WebLogic
Server and automatically attached Optimizeit with WebLogic Server. Now the Optimizeit
view in the message pane demonstrates the memory profiling information of WebLogic. See
Figure 16 for details.
Optimizeit Suite has many features available to help detect critical memory leaks,
performance issues, deadlocks, etc. This paper just explained a snapshot of some of the
features. Read the Optimizeit Suite product documentation for more information about other
features of Optimizeit Suite.
Entity beans require a persistent store such as a database. For our testing, we will use the
Borland® JDataStore™ database as the persistent store. JDataStore installs with the default
installation of JBuilder X and is licensed for development purpose only.
20
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
From the JBuilder toolbar, click Tools | Configure Servers. The Configure Servers window
opens.
From Configure Servers window, click WebLogic Platform 8.x | click the Required
Libraries tab | click ADD | from the Select One or more Libraries window, select
JDataStore | click OK.
You should see a JDataStore entry under the Required Libraries tab of Configure Servers
window. Click OK. See Figure 17 for details.
Note: The above exercise was necessary to add JDataStore libraries (JAR files) to the WebLogic
classpath, so that when WebLogic starts, it can find the JDataStore drivers.
21
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Create a project
Create a project and assign WebLogic Platform Server 8.x as the target application server for
the project. Create an EJB module. To get help on how to perform the above operations, see
to the previous section in this paper, “Working with session beans.”
For this exercise, enter the name of the project as WebLogicEntProject in the directory
C:\Projects\WebLogic81\WebLogicEntProject. Enter the EJB module name as
WebLogicEntMod.
An entity bean represents the state of real-time data from the database table(s). With JBuilder,
users can create entity beans in following ways:
• First create entity beans and then generate a database from the entity beans.
• Generate entity beans from an existing database.
For this exercise, let’s focus on generating entity beans from an existing database.
Right-click on the editor pane. Click Import Schema from Database. See Figure 18
Figure 18: Importing schema from a database using the JBuilder visual EJB Designer
That brings up the Database Schema Provider window. Click the Choose Existing
Connection button. Select the following database URL.
jdbc:borland:dslocal:C:\Borland\JavaStudio\samples\JDataStore\datasto
res\employee.jds
22
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Change the value of JNDI name to JDataStoreDS. Now you should have the following
values in the Database Schema provider window.
Driver: com.borland.datastore.jdbc.DataStoreDriver
URL:
jdbc:borland:dslocal:C:\Borland\JavaStudio\samples\JDataStore\datasto
res\employee.jds
Username: Sample
Password: <leave this empty>
Database name:
borland:dslocal:C:\Borland\JavaStudio\samples\JDataStore\datastores\employee.jds
Figure 19: JBuilder Database Schema Provider—to create entity beans from database
schema
23
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Note: JBuilder imports all the tables from the specified database into the Structure pane. Now
developers can see the existing tables and create entity beans visually from the tables they need.
Expand JDataStoreDS from the JBuilder structure pane to see the list of tables available in
the database. You can create entity beans visually just by right-clicking a table name and
clicking Create CMP 2.0 Entity Bean or Create BMP Entity Bean.
For this exercise, let’s create a CMP 2.0 Entity Bean for the EMPLOYEE Table. Right-click
EMPLOYEE from the structure pane. Click Create CMP 2.0 Entity Bean. This creates a
Visual Employee Entity Bean in the editor pane. See Figure 20.
Figure 20: Visually creating a CMP 2.0 Entity bean from a database table.
Note: JBuilder creates the EJB files Employee.java, EmployeeBean.java, and EmployeeHome.java.
To check the source code, right-click the entity bean Employee, and click View Bean Source.
JBuilder provides wizards to create Session Façade and Struts client from entity beans. This
wizard creates state-of-the-art J2EE and Struts patterns to access the entity bean from outside.
24
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
This saves significant time for developers who otherwise would have to write lot of code
manually and need quite a bit of domain expertise in the J2EE and design aspects.
To launch the DTO/Façade Wizard, right-click the Employee entity bean from the JBuilder
editor pane. Click Launch DTO/Façade Wizard. See Figure 21 for details.
Figure 21: Launching DTO/Session Façade Wizard for an employee entity bean
In DTO and Session Façade Wizard – Step 1 of 8, check the checkbox against Generate
Struts Client. See Figure 22.
Figure 22: Creating advanced patterns (including Struts) from an entity bean
Keep clicking Next in all windows until you reach DTO and Session Façade Wizard – Step
8 of 8.
25
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Click New against Web Module and follow the Web Module Wizard to create a new web
module named WebLogicWebMod. See Figure 23.
Figure 23: Providing a Web module for hosting Struts environment in WebLogic
Click Finish.
Note that with this Wizard, JBuilder creates a Session Façade, Business Delegate, Service
Locator, DTO, DTO Assembler, and Struts framework from the entity bean. All technical
artifacts and configurations for the above patterns and files are created automatically,
allowing the developer to focus on the business implementation instead of spending time in
the complex technical details of the EJBs, Struts, and patterns.
Figure 24 shows the JBuilder screen shot after the Wizard was run.
26
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Figure 24: JBuilder has created the advanced patterns for the entity bean
27
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
In the Application Module Wizard – Step 3 of 7, check the checkbox under the “include”
column to include WebLogicEntMod.
In the Application Module Wizard – Step 4 of 7, check the checkbox under the “include”
column to include WebLogicWebMod.
Click Finish.
Click Run Project icon to Start WebLogic Server. See Figure 26.
Figure 26: WebLogic Server has started within JBuilder Message Pane
28
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Note: If WebLogic Server is already running within JBuilder, you don’t have to stop it and start it
again. If it’s already running, you can skip the “Start WebLogic Server” section.
Note that JBuilder has already created a Struts client to test the entity bean Employee.
From the JBuilder project pane, expand WebLogicWebMod | expand Module Directory |
expand employeeDelegateClient, right-click index.jsp, and click Web Run using WebLogic
Server.
Now the JSP (struts client) runs within JBuilder editor pane as shown in figure 28.
29
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Click employeeFinderIndex URL from the editor pane and then click
employeeFindByPrimaryKey URL from the next screen. You should see a screen as shown
in Figure 29.
Figure 29: A JBuilder Struts application requesting that a value be entered to look for an
employee
30
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Type 2 under the EmpNo. Click Submit. JBuilder should navigate to a screen with the
employee information with EmpNo 2. See Figure 30.
Note: This information is from the JDataStore database through a Struts and EJB layer interface.
EmployeeSessionFacade retrieves the employee information from the Employee entity bean. The
Struts interface connects to the Session Facade and displays the employee information. This is a
typical technical implementation of J2EE application using Struts.
31
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Local debugging
Stop WebLogic Server in JBuilder by clicking the square red icon at the bottom left corner of
the JBuilder message pane.
Click the Debug Project icon from the JBuilder toolbar. WebLogic Server now starts in
debug mode within the JBuilder message pane. See Figure 31 for details.
After WebLogic has started in debug mode, developers can assign break points to the source
code and use the debugging capabilities of JBuilder to debug the application.
Remote debugging
JBuilder can remotely debug an already running application in a remote server – in this case
WebLogic Server. To remotely debug an application, WebLogic Server must be started in
debug mode.
32
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
set JDATASTORE_CLASSPATH=C:\Borland\JavaStudio\lib\jds.jar;
C:\Borland\JavaStudio\lib\jdsserver.jar
set
CLASSPATH=%WEBLOGIC_CLASSPATH%;%JDATASTORE_CLASSPATH%;%POINTBASE_C
LASSPATH%;%JAVA_HOME%\jre\lib\rt.jar;%WL_HOME%\server\lib\webservi
ces.jar;%CLASSPATH%
33
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Enter the following configuration values in the Runtime Configuration Properties window.
Name: RemoteDebug
Build target: <None>
Type: Server
Check the Enable Remote Debugging checkbox, click Attach and enter the Address as
5555.
Note: The address specified here must be the same as the port number specified in the WebLogic
Server as debug options. JBuilder opens a socket connection to the WebLogic Server and attaches
to WebLogic using that port number.
34
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
35
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Now you can assign breakpoints to the Java files within JBuilder. A breakpoint can be
assigned just by clicking at the beginning of a source code line in JBuilder editor pane.
Note: JBuilder puts a green checkmark next to all valid breakpoints and a red crossmark next to all
nonvalid breakpoints.
If you have a breakpoint set in any of the EJB files and the breakpoint has reached by the
struts client, you will see JBuilder debugger stopping execution at the breakpoint.
When the execution reaches at the breakpoint (in our case by the Struts client), the JBuilder
debugger puts a blue arrow mark on top of the breakpoint indicating that the execution has
stopped at that line. See Figure 34.
36
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Figure 35: The JBuilder remote debugger has stopped at the breakpoint
Now you can follow debugging techniques such as step over, step into, step out, etc.
To learn more about creating JMS application using WebLogic Server, visit the link http://e-
docs.bea.com/wls/docs70/jms/implement.html.
37
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Name: DemoJMSConnectionFactory
JNDIName: DemoJMSConnectionFactory
Leave other default values and click Create. Click the Target and Deploy tab. Check the
checkbox for myserver (or whatever server name you are using). Click Apply.
From the WebLogic Server Console, expand JMS under Services and click Stores. Click
Configure a new JMSFile Store.
Name DemoJMSFileStore
Directory C:\ThirdParty\bea\DEMOJMSFileStore
Click Create.
38
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Name: DemoJMSServer
Store: DemoJMSFileStore
Click Create. Leave other defaults. Click Targets and Deploy tab and select myserver as the
Target.
Create a queue
From the WebLogic Server Console, expand JMS under Services. Expand Servers >
DemoJMSserver | Destinations | Click Configure a new JMSQueue.
Name: DemoJMSQueue
JNDIName: DemoJMSQueue
Create a project, assign WebLogic Platform Server 8.x as the target application server for the
project, and create an EJB module. For help with how to perform the above operations, see
the previous section, “Working with session bean.”
For this exercise, enter the name of the project as WebLogicJMSProject in the directory
C:\Projects\WebLogic81\WebLogicJMSProject and enter the EJB module name as
WebLogicJMSMod.
39
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
40
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Figure 36: JBuilder created a MDB visually and provided a GUI to configure the MDB
Note: The on Message () method gets executed when the MDB receives a message. In this case,
the on Message () method will print the received message.
41
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
import javax.jms.TextMessage;
import javax.jms.JMSException;
Make the project and make sure that there are no build errors.
Create a runtime configuration to start WebLogic Server within JBuilder. From the main
JBuilder menubar, click Run |Configurations | click New from the Runtime Configurations
window.
Enter Name as WebLogic Server, Type as Server, and Build Target as Make.
Start WebLogic Server within JBuilder by clicking Run Project icon from JBuilder toolbar.
Click File| New Class | Enter Class name as JMSClient | Click OK.
42
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
JMSClient.java
package weblogicjmsproject;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import java.util.Hashtable;
import javax.jms.Message;
QueueSession queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender(queue);
Message message = queueSession.createTextMessage("Hello Message Bean");
queueSender.send(message);
queueConnection.close();
System.exit(0);
}
}
Make the JMSClient.java file. Check for compilation errors. Run JMSClient.java by right-
clicking JMSClient.java | Run using defaults. After a successful execution, the following
message appears on the WebLogic Server:8080 tab: Message from WebLogicJMS = Hello
Message Bean. See Figure 37.
43
™ ® ®
EJB Development Using Borland JBuilder X and BEA Weblogic Server 8.1
Figure 37: JBuilder showing successful execution of MDB in WebLogic running within
JBuilder
Made in Borland® Copyright © 2004 Borland Software Corporation. All rights reserved. All Borland brand and product names
are trademarks or registered trademarks of Borland Software Corporation in the United States and other countries. Microsoft,
Windows, and other Microsoft product names are trademarks or registered trademarks of Microsoft Corporation in the U.S. and
other countries. All other marks are the property of their respective owners. Corporate Headquarters: 100 Enterprise Way, Scotts
Valley, CA 95066-3249 • 831-431-1000 • www.borland.com • Offices in: Australia, Brazil, Canada, China, Czech Republic,
Finland, France, Germany, Hong Kong, Hungary, India, Ireland, Italy, Japan, Korea, Mexico, the Netherlands, New Zealand,
Russia, Singapore, Spain, Sweden, Taiwan, the United Kingdom, and the United States. • 22123
44