---------------------------------
EJB Rapid Development
---------------------------------
development tools:
IDE: Eclipse 2.1 M4
Builder: Ant 1.5.1
Generator: xdoclet 1.2.0B2
Appserver: Orion 1.6.0Beta
DBMS: mysql 3.23.52
Brief description:
Eclipse - a nice Java integrated development environment, I believe that many people are already in use.
Ant - Similar to the Make tool under Linux, perform various tasks in the form of batch processing (such as file copy, editing
Translation, packaging, etc., and custom tasks).
XDoclet - A code automatically generates tools, which is mainly used in EJB rapid development with Ant tools. through
Insert some specific Javadoc tags in your bean implementation of the source file, resolve all kinds of files
For example, interface files and deployment description files. At the same time, there are also many concepts of design patterns in version 1.2.0, such as
Automatically generate DAO and ValueObject objects, SessionFacade objects, and some tool classes.
Orion - small appserver, but the function is very strong, it is gradually supporting EJB2.0.
MySQL - not to say, my favorite relational database.
Why use the above development tool combination - first they are free, and almost all open source. its
The function is powerful, which is low for developers' machine configuration requirements. Support CMP / CMR, JSP in EJB2.0
And JMS. Whether it is C / S application or B / S app, it can quickly build a test platform. Obviously, this
The tool combination can be extremely developed, I will call it EJB fast development tool combination here.
Simple example:
A stateless sessionbean. The file organization structure is as follows:
XDoclet_examples
|
| --- build.xml
| --- SRC
| | | --- COM
| | | --- Laysman
| | | --- Test
| | | --- xdoclet
| | --- Tellerbean.java
| | --- TellerClient.java
| --- Target
| | | --- Classes
| | | --- Gen-SRC
| | --- Meta-INF
Development Process:
1). Write a TellerBean implementation class
2). Write the build.xml used by Ant
3) Automatically generate various interface files and deployment description files and packaged (JAR)
4) Deploy to Orion
5) Write a remote test client
---------------- 1. Write sessionBean to achieve class tellerbean.java ------------------
Package com.laysman.test.xdoclet;
Import javax.ejb. *;
/ **
* @ Ejb.bean name = "teller" jndi-name = "ejb / teller" type = "stateless" view-type
= "Both"
* @ Ejb.transaction type = "required"
* @ Ejb.transaction-type type = "container" * @Author Laysman 2003-1-15
* /
Public Abstract Class TellerBean Implements SessionBean {
SessionContext sessionContext;
Public void ejbcreate () throws createException {
}
/ **
* @ Ejb.interface-method view-type = "both"
* @ Ejb.transaction type = "required"
* /
Public String Tell () {
Return "Hello Greeting";
}
Public void ejbactivate () {
}
Public void ejbpassivate () {
}
Public void setsessionContext (sessionContext CTX) {
THIS.SESSIONCONTEXT = CTX;
}
Public void ejbremove () {
}
}
--------------- 2. Write the build.xml used by Ant (this basically can be used as a magic board) -------
XML Version = "1.0"?>
fileset>
fileset>
path>
Name = "xdoclet" ClassName = "xdoclet.doclettask" ClasspathRef = "Samples.class.path" /> Name = "ejbdoclet" ClassName = "xdoclet.modules.ejb.ejbdoclettask" ClasspathRef = "Samples.class.path" /> target> target> destdir = "$ {gen-src.dir}" MergeDir = "Parent-fake-to-debug" ExcludedTags = "@ version, @ Author, @ TODO" EJBSPEC = "2.0" FORCE = "false" Verbose = "false"> fileset> DAO> destdir = "$ {meta-inf.dir}" ValidateXML = "true" Mergedir = "fake-to-debug" Xmlencoding = "GB2312"> deploymentdescriptor> ejbdoclet> target> destdir = "$ {classs.dir}" ClasspathRef = "Samples.class.path" Debug = "on" DepRecation = "ON" Optimize = "OFF"> javac> target> fileset> fileset> jar> target> target> provject> ------------------ 3. Automatically produce various interface files and deployment description files and package (jar) ---------- Run Ant -BuildFile Build.xml Jar in the directory where build.xml is located This will automatically generate the target directory and the various files generated as for this directory, including Teller-EJB. .jar package. ------------------ 4. Deploy to Orion ---------- Just add a line in [orion.dir] /config/application.xml: Of course, you have to copy the Teller-Ejb.jar under the target directory to the [Orion.Dir] / Applications directory ------------------ 5. Write a remote test client TellerClient.java ---------- Package com.laysman.test.xdoclet; Import javax.naming.context; Import javax.naming.initialcontext; Import javax.rmi.portableremoteObject; Import java.util. *; / ** * @Author Laysman 2003-1-15 * / Public class tellerclient { Public static string context_factory = "com.evermind.server.rmi.rmiiniti AlContextFactory "; Public static string provider_url = "ORMI: // Localhost"; Public static void main (string [] args) { Try { Hashtable env = new hashtable (); Env.put (Context.initial_Context_Factory, Context_Factory); Env.put (Context.Provider_URL, Provider_URL); Env.put (Context.Security_Principal, "admin"); Env.put (Context.security_credentials, "laysman"); / ** * CREATE Access to the Naming Context. * / Context context = new initialcontext (env); / ** * Lookup the TellerHome Object * / Object homeObject = context.lookup ("teller"); // Narrow the Reference to a TellerHome TellerHome Home = (TellerHome) PortableRemoteObject.narrow HomeObject, TellerHome.Class; Date begin = new date (); For (int i = 0; i <10; i ) { Teller session = home.create (); System.out.println (session.tell ()); } Date end = new date (); System.out.println ("Last:" String.Valueof End.gettime () - begin.gettime ()) "ms"); } catch (exception e) { E.PrintStackTrace (); } } } Note: JNDI environment parameters in the source file are for Orion AppServer, which should be made for different appserver Corresponding modifications (of course, better ways is to modify using JNDI.Properties profiles).