Developing Java EE applications using myeclipse: Creating EJB 2 Session Bean Project with Xdoclet (iv)

Source: Internet
Author: User

MyEclipse time limit seconds kill! Event Hot Start >>

"MyEclipse Latest version download"

Iv. running Xdoclet code generation

You should perform xdoclet every time you change the Xdoclet EJB configuration, Application server settings, or modify the Xdoclet annotation of any EJB bean implementation class.

It is now a good opportunity to execute Xdoclet on the FIRSTEJB project and test the new Xdoclet settings, because trader EJB has not yet been extended with the new Xdoclet annotation business method.

1. Right-click FIRSTEJB and select Myeclipse>run XDoclet.

2. Monitor the console view of the exception output message from the Xdoclet-build script.

to run the console output of the Xdoclet operation

After running Xdoclet, the FIRSTEJB project includes new versions of the trader and Traderhome interfaces as well as Ejb-jar.xml and jboss.xmldeployment descriptors.

Xdoclet the contents of a post-build EJB project

Note : When you create the Traderbean.java class in section 2nd, specify the Java package name as COM.GENUITEC.TRADER.EJB and emphasize that the package name should end with an. EJB. This is because the standard EJB Xdoclet package replacement subtask can create a corresponding Java package name ending with. Interfaces and add the resulting EJB and home interface to it. In this example, the Com.genuitec.trader.interfaces package is created, which contains the trader EJB and Traderhome interfaces.

v. Create session Ejb–part 2

In part 1, you see the process of creating a Traderbean class. In this section, you add business methods and Xdoclet comments to the Traderbean class, and then use Xdoclet to update the trader and Traderhome interfaces that were previously created.

When you create the initial Traderbean.java class, the EJB-created wizard adds a sample business method that you can use as a pattern for adding your own business methods. Note that this method includes the Javadoc tag @ejb. Interface-method, which identifies the method as being implemented by the EJB interface method in this custom Ejbdoclet tag. When Xdoclet is running on this class, the Trader.java EJB interface class is modified to include all @ejb.interface-method annotations.

Traderbean Example Methods
12345678910 /** * An example business method Code class= "Java preprocessor" >* * @ejb. Interface-method view-type = "Remote" /code>* * @throws ejbexception thrown if Method fails due to system-level error. */ public void replacewithrealbusinessmethod ()   throws ejbexception { //rename and start putting your business Logic here< BR >} *

1. Double-click Traderbean.java to open in the editor.

2. Add the following two business methods before the last parenthesis, and then press CTRL + S to save.

123456789101112131415161718192021222324252627282930313233 /*** Buys shares of a stock for a named customer.** @param customerName String Customer name* @param stockSymbol String Stock symbol* @param shares int Number of shares to buy* @return Number of shares purchased** @ejb.interface-method*/ public int buy(String stockSymbol, int shares) {System.out.println("Buying "+shares+" shares of "+stockSymbol + ". Good move.");return shares;}/*** Sells shares of a stock for a named customer.** @param customerName String Customer name* @param stockSymbol String Stock symbol* @param shares int Number of shares to buy* @return The number for shares sold** @ejb.interface-method*/public int sell(String stockSymbol, int shares) { System.out.println("Selling "+shares+" shares of "+stockSymbol);return shares;}

3. Run Xdoclet on the FIRSTEJB project to synchronize trader and Traderhome classes and deployment descriptors.

4. Double-click Trader.java in the Com.genuitec.trader.interfaces package. Note Add buy () and sell () business methods.

123456789101112131415161718192021222324252627282930313233 /*  * Generated by XDoclet - Do not edit!  */ package com.genuitec.trader.interfaces; /**  * Remote interface for Trader.  * @author XDoclet  */ public interface Traderextends javax.ejb.EJBObject {/** * Buys shares of a stock for a named customer. * @param customerName String Customer name * @param stockSymbol String Stock symbol * @param shares int Number of shares to buy * @return Number of shares purchased */public int buy( java.lang.String stockSymbol,int shares )   throws java.rmi.RemoteException;/** * Sells shares of a stock for a named customer. * @param customerName String Customer name * @param stockSymbol String Stock symbol * @param shares int Number of shares to buy * @return The number for shares sold */public int sell( java.lang.String stockSymbol,int shares )   throws java.rmi.RemoteException; }
For more information, please visit MyEclipse Chinese network >>

Developing Java EE applications using myeclipse: Creating EJB 2 Session Bean Project with Xdoclet (iv)

Related Article

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.