Step-by-step development of EJB with JBuilder4 (from China-pub)

Source: Internet
Author: User
Tags configuration settings contains empty interbase client
Step by step using JBuilder4 to develop EJB Author: Liao Jia release time: 2001/02/07 Article summary: This article provides a step-by-step example of how to develop EJBS in a JBUILDER4 integrated development environment. These steps are simple and easy to understand for people who understand the EJB architecture and general programming rules. The purpose is to enable us to master the development of distributed multilayer application system in JBuilder4 under the simple, fast method to achieve extrapolate effect. Body:

Step by step using JBuilder4 to develop EJB
First, Introduction

The Enterprise Java Beans (EJB) 1.1 specification formally defines a Java server-side component model and the application server's programming interface. This type of component created by developers is called Enterprise Beans, which contains business logic for the enterprise. Enterprise beans runs on the EJB server, which provides services such as transaction and security for beans. Developers do not need to program to implement these low-level, complex services, and only need to know that these services are available when the beans they develop require these services. In this way, they can focus on dealing with the business logic within the beans.
Distributed multi-tier application systems typically consist of a client layer running on a local machine, a middle tier running on the application server that contains business logic, and a backend enterprise information system (typically such as a database). And the focus here is on how to develop EJBS, the middle-tier stuff.
This article provides a simple example of how to develop EJBS in a JBUILDER4 integrated development environment. These steps are simple and easy to understand for people who understand the EJB architecture and general programming rules. The purpose is to enable us to master the development of distributed multilayer application system in JBuilder4 under the simple, fast method to achieve extrapolate effect.

Second, the environment configuration

1. Introduction
Borland JBuilder is the best Java development tool based on the Java 2 Enterprise platform, creating cross-platform environments, and pure Java end-to-end solutions. JBuilder4 is a powerful rapid development tool (RAD) for developing EJBS and java-based applications. It provides an integrated development environment and a number of wizards that lead us step-by-step development of our applications.
This article will guide readers through the development and configuration of two classes of EJBS (session beans and entity beans) step-by-step with the wizards and features provided by JBUILDER4.

2, installation and configuration
Installation
All of the examples in this article are done on the Windows NT platform. Because Java itself has cross-platform features, the basic steps on other platforms are the same. To complete all the examples in this article, the required software is: JDK1.2.2, Borland JBuilder4, inprise application Server 4.1, InterBase 5.5, and InterClient1.6. You can use another database system instead of InterBase and interclient, as long as your database system has a JDBC driver. All the software listed previously is available on the website of Sun Company and Borland/inprise Company, which can be downloaded to meet the needs of learning. As shown in the following table:
  
   Install JBuilder4: First install JBuilder4 Foundation, then install JBuilder 4 Enterprise, and you can also install the documentation and examples that came with JBuilder4 (in this article, JBuilder4 installed in D:\JBuilder4). After the installation is complete, start JBuilder4, select "File"-"New", and a dialog box will pop up, allowing you to choose what application to build. By clicking on the "Enterprise" page, you will find that all items in it are gray and not selectable. Don't worry, wait for us to install and configure Inprise application Server.
After that, there will be.
   Install JDK1.1.2: Follow the prompts to install (the JDK is installed in D:\jdk1.2.2 in this article).
   Install inprise application Server 4.1: Configure the Osagent port to be 14000 (default) when installing IAS41 IAS4.1 is installed in the D:\IAS41 directory in this article.
   install InterBase and interclient: Because in the following entity Beans example, we will be accessing the database, where we install InterBase5.5 and a third class of JDBC driver InterClient1.5 for InterBase5.5. Follow the installation prompts (in this article, InterBase is installed in the D:\InterBase corp\interbase directory; interclient installed in D:\InterBase corp\interclient directory).

Configuration
We need to configure JBUILDER4 to let it know the existence of IAS41. Start JBuilder4 and select "Tools"-"Enterprise Setup" in the menu bar. In the Enterprise Setup window, as shown in Figure 1. In the "CORBA" page, select "Visibroker" in "Select Configuration" and click on the "Edit" button next to configure "Path of ORB Tools" in the "Edit Configuration" window As a "bin" subdirectory in the Inprise Application Server installation directory, "D:/ias41/bin" in this article (note: The path symbol here is "/"), as shown in Figure 2.
  
Figure 1
  
Figure 2
On the Application Server page, as shown in Figure 3, configure the IAS installation directory as "D:/IAS41" (note: The path symbol here is "/").
  
Figure 3
After these two configurations are complete, click OK, and then restart JBuilder4.
In addition, we need to build a library of JAR files Inprise application server so that JBUILDER4 can rely on classes in the library to compile the project.
In JBuilder4, select Project-"Default project Properties ..." In the menu, select the "Required librares" page in the "Paths" page in the open window, as shown in Figure 4, and then click "Add ..." Button. In the select one or more Libraries window, click the "New ..." button. In the New Library Wizard window, click the "Add" button. Add all the jar files in the Ias41\lib directory. As shown in Figure 5. When finished, figure 6. Set the new Library name: IAS.
  
Figure 4
  
Figure 5
  
Figure 6


Third, session Beans

   1. Development session Beans
Once the preparations are complete, we can begin our JBUILDER4--EJB journey. First, we'll build a JBuilder project. In this project, we will write a stateless (stateless) session Beans, named Tellerbean. In this session bean, there is a way to return an assumed number that represents the number of a bank teller. When we're done, we'll also create a test "customer" to access the bean.
Open your JBuilder4, and if JBuilder4 has a default open item, close it first. Then, create a new project.
Steps:
1. Select "File"-"New Project ..."
2, set project name, project directory name is "QuickStart", and set root path to D:/project. (Note the path), as shown in Figure 7.
3, click "Finish".
  
Figure 7
Then we'll build an EJB Group so that whenever we compile the project, JBUILDER4 will automatically build a configurable jar file that contains our EJBS.
Steps:
1, select "File"-"New ..."-"Enterprise" tag-"Empty EJB Group"-"OK".
2. Set name to "QuickStart" in the "Empty EJB Group Wizard" window.
3, click "OK". As shown in Figure 8.
  
Figure 8
Next, we start to build the bean. JBUILDER4 provides a guide to building EJBs, and here we are, of course, using wizards.
Steps:
1, select "File"-"New ..."-"Enterprise" label-"Enterprise JavaBean".
2. After clicking "OK", the wizard prompts us to select the EJB group, of course, with the EJB group we just created.
3, click "Next", set class name for Tellerbean. Others remain unchanged. As shown in Figure 9.
  
Figure 9
4, click "Next", set "Bean home name" for Tellerhome. Others remain unchanged, as shown in Figure 10.
  
Figure 10
5, click "Finish".
In this way, you'll see three classes in the left window of JBuilder4, where Tellerhome and Teller are the interfaces that are implemented for the EJB container; Tellerbean is our own bean. We will add a method to this bean.
Select the "Tellerbean" class, and then add the following method to the class:

public int Gettellerno () {
return 1;
}

Save all the files. Then compile the project. (Click the toolbar and icon).
Now we need to add our signature to the remote interface so that the EJB container can expose our approach to the remote-invoked client.
Steps:
1, double-click the Item pane: Tellerbean.java. You can see the Tellerbean.java source files in the content pane.
2, under the Tellerbean label, click on the Bean tab, and then select the methods tag.
3, select int Gettellerno (). As shown in Figure 11.
  
Figure 11
Now we have finished coding the EJB. The next thing you'll do is to configure the descriptor.
The configuration descriptor is one of the important components of EJB. It splits the EJB code and the EJB configuration settings. In this way, the application can be segmented and adjusted without affecting the source code.
In fact, we already have a configuration descriptor in our project. When we took advantage of the EJB Group Wizard, we generated the. When we use the wizard, it generates Tellerbean Java code, adds a corresponding configuration descriptor entry, and now we just need to tweak it.
Steps:
1. In the Project pane, double-click Quickstart.ejbgrp, in the structure pane below, expand Tellerbean, click Container transactions. As shown in Figure 12.
  
Figure 12
2, in the right side of the content pane, click the lower "ADD" button, add a "Required" Transaction attribute to our method. As shown in Figure 13. This "Required" Transaction attribute will work on all of the methods and interfaces of the bean.
    
Figure 13
3. To verify that the configuration descriptor is set correctly, we can verify the configuration descriptor settings by clicking the icon on the widget bar at the top of the content pane. As shown in Figure 14, we see that the information obtained from validation is: 0 errors,0 warnings.
  
Figure 14
4, save all the files, and then compile the project. (Click the toolbar and icon).
Now, all the server-side work we've done. Below we will build a Java customer to test our written EJB.
Steps:
1. Select "File"-"New ..."-"Enterprise" tag-"EJB Test Client".
2, click "OK", in the EJB Test Client wizard window, set class to Client
Simply select Generate main function. Then click "OK", as shown in Figure 15.
  
Figure 15
3. In the construction method of the established class, you can see a "try...catch" statement block. In this statement block, an instance of the context, a tellerhome Jndi lookup, a return object narrow of a reference tellerhome type are included.
4, after these lines of code, still in the "Try...catch" statement block, add the following code:
Teller teller=tellerhome.create ();
int T=teller.gettellerno ();
System.out.println ("Using Teller No is:" +t);
These lines of code create a bean instance, call a remote method, and then output the results.
Finally, in order to be able to invoke the remote interface, the client program needs to establish RMI/IIOP stubs.
Steps:
1, in the Project pane, right click on "Tellerhome.java", select "Properties."
2, in the pop-up window, select the "Build" tab, then select "Visibroker", and then only select "Generate IIOP". As shown in Figure 16.
  
Figure 16
3, save all the files, and then compile the project. (Click the toolbar and icon).
Now, we have completed the development of this stateless session bean and test customer.

   2. Configure Session Beans
We will execute this bean inside the JBUILDER4 built-in EJB container.
Steps:
1. First, run Visibroker Smart Agent. ("Tools"-"Visibroker Smart Agent")
2, set up a configuration to run the EJB container. "Run"-"Configuration ...", edit the "default" configuration, in the EJB tab, as shown in Figure 16-1.
  
Figure 16-1
3, click on the tool bar, the running container. Wait for the container to initialize.
4, with the right mouse click on the Project window Client.java, select "Run".
In the message pane at the bottom of the JBuilder4 window, you will see the following message:
"D:\JBuilder4\jdk1.3\bin\javaw-class .........
Using Teller no:1 "
At this point, your test client has successfully invoked the remote interface.


Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.