Easily write EJB components using Ejbframe

Source: Internet
Author: User
Tags resource

The EJB (Enterprise Java Bean) is the core technology in EE, defining the Enterprise Application component specification. By encapsulating the business logic in the EJB component, the development of the 3-tier architecture application system is realized.

However, the EJB specification is relatively complex, and the EJB code needs to write EJB's home interface, remote interface and EJB implementation class. The EJB specification has many conventions for these interfaces and classes, and it is inconvenient and error-prone to write them manually. Here, I recommend to you a tool, Ejbframe. Ejbframe is a tool provided by MINIJ2EE to generate the EJB Component Framework source program, through GUI interface operation can automatically generate the correct EJB home interface, EJB remote interface and EJB implementation class framework source program, and can also generate access to the database, Access the URL resource and send and receive the code for the message. As long as you fill in the generated code, add your business logic to facilitate the completion of the EJB component writing.

Before introducing how to use Ejbframe, let's briefly review the basics of EJB. In EJB specification 1.1, the EJB is divided into stateful session bean,stateless session Bean and entity bean three types of enterprise beans. The method for creating and locating EJBS is defined for each ejb,home interface; The remote interface defines the EJB's business logic method; The EJB class needs to implement methods corresponding to the home interface and the remote interface, which will be used by EJB Container is used to provide client requests for EJBS. For the EJB home interface, remote interface, and EJB class authoring methods, refer to the MINIJ2EE User manual (http://www.minij2ee.com/document/), which has a detailed description. Here, we are going to talk about how to use Ejbframe to facilitate the generation of EJB framework code.

Let's take the example of developing a simple stateful session bean to demonstrate how to use Ejbframe. Our demo EJB only provides a Gethelloworld method that returns a "Hello World from ejb!" The string. Currently, the Ejbframe tool needs to run on Windows (http://www.minij2ee.com/download/) and Linux-enabled versions are under development.

We start the Ejbframe program, enter the Ejbframe main interface, and then do the following:

1. Specify the name of the EJB remote interface:

In the Remote Interface Name box in the EJB information, enter the name of the EJB remote interface, where our EJB is called Hello and enter hello. Once entered, the Ejbframe tool automatically generates an EJB home interface named HELLOHOME,EJB class whose name is the HELLOEJB,EJB exception class whose name is Helloexception, The Jndi name of the EJB deployment (the value specified in Ejb-jar.xml) is Hellobean.

2. Select the type of EJB:

Select session in EJB type in EJB information, because our EJB is the session bean.

3. Add method for remote interface:

As mentioned above, our EJB provides a Gethelloworld method. Press the Add button in the remote Interface methods to eject the Add Method dialog box. In the Add Method dialog box, enter Gethelloworld in the return type selection String,method name, and press OK. In the Add Method dialog box, the Addon code area is used to select the additional codes that are generated for this way, and selecting the database will generate the data access code, select POP3 will generate the code to receive email, and select SMTP to generate the code to send the message. Selecting the URL will generate code to access the URL resource. Since our EJB is simpler, there is no need to generate additional code

4. Add a method for the home interface:

We need to add a create method for the EJB's home interface to create the EJB object. Press the Add button in home Interface methods to eject the Add Method dialog box. In the Add Method dialog box, type create in the method type Select Create Method,method name, and press OK.

5. Generate EJB Framework Code

By pressing the Generate button on the main interface, a DOS window appears, showing:

done!

Press any key.

Hello.java,hellohome.java,helloejb.java and Helloexception.java are generated in the current directory.

6. Complete the Code

Open Helloejb.java and modify the public String Gethelloworld () throws Helloexception method as follows:

public String getHelloWorld() throws HelloException
{
return "hello world from EJB!";
}

Then, run Javac *.java in the directory. Finally, Hello.class,hellohome.class,helloejb.class and Helloexception.class were generated. In this way, an EJB is done.

Here are some common questions that you can refer to if you follow the steps above.

No success screen after pressing generate button

1. Please check if Java program is loading path, ejbframe program calls Java program to execute Java class that generates code

2. Please check that the Genframecode.class file is in the same directory as the Ejbframe.exe.

Javac Compile Code Error

1. Please check that Minij2ee.jar and Mail.jar are in classpath, and that these two files are in the Lib subdirectory of the MINIJ2EE directory.

2. Please check the program code.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.