[Editor Press] In order to help domestic J2EE beginners, compile J2EE some documents, expect to help the majority of Java enthusiasts. This article will describe how to develop, deploy, and run a client / server application using EJB development. The client is run as a Java independent application, implemented by the ConverterClient.java class. It implements a simple real-time session, which is mainly implemented by calling server-side EJB Class CONVERTEREJB. Java through client applications. If you have already installed J2EE, you can find these examples in the Doc / Guides / EJB / Examples / Converter directory. To achieve the simple example described herein, you need to complete the following tasks: • Writing and compiling EJB programs • Creating J2EE Apps · Packing EJB (.jar) · Deploy J2EE Apps · Write and Compile Client Programs · Run the Section of the Client Und The above working tasks will be briefly described with the knowledge points involved. Premise the premise of implementation of this paper is that you have a J2SE SDK downloaded by JavaSoft.com or related operating system vendor website, and the J2EE SDK (www.javasoft.com download) installed in accordance with the corresponding operating system version is installed and properly configured. For J2SE and J2EE installation, configuration, and other further information, see the product related documentation. EJB encoding each EJB program must require the following code: • Remote interface · Home interface · Enterprise Bean Class Remote Interface Define the remote interface defines the business method that the client can call. These business methods are implemented in the server components of the server side, and the CONVERTER.JAVA encoding involved in this article is as follows:
Import javax.ejb.ejbobject; // Introduced must be packaged
Import java.rmi.remoteexception;
Public interface control {// must inherit EJBOBJECT class
/ * Define how the client can call * /
Public Double Dollartoyen (Double Dollars) Throws RemoteException;
Public Double Yentoeuro (Double Yen) Throws RemoteException;
}
The local interface encoding the local interface defines the method of the member Xu client creation, finding, or mobile EJB. The local interface class ConverterHome interface covered in this article defines a CREATE method, returns the remote interface type, the encoding is as follows:
Import java.io.serializable;
Import java.rmi.remoteexception;
Import javax.ejb.createException;
Import javax.ejb.ejbhome;
Public interface converTerhome Extends ejbhome {
Converter Create () throws RemoteException, CreateException;
}
Enterprise Components (EJB) Encoding Enterprise Components (EJB) in this article is a stateless session component, named ConvertRejb.java, which implements two business methods: DollArtoyen and Yentoeuro, defined by remote interface Converter Defined clients The access method is consistent, and the coding is as follows:
Import java.rmi.remoteexception;
Import javax.ejb.sessionbean; import javax.ejb.sessionContext;
Public class converterejb imports sessionbean {
Public Double Dollartoyen (Double Dollars) {
Return DOLLARS * 121.6000;
}
Public Double Yentoeuro (double yen) {
Return Yen * 0.0077;
}
Public convertEREJB () {}
Public void ejbcreate () {}
Public void ejbremove () {}
Public void ejbactivate () {}
Public void ejbpassiVate () {}
Public void setsessionContext (sessioncontext sc) {}
}
Compiling EJBs now need to compile the above three classes, and compile them slightly on the UNIX platform and the NT / 9X platform, compile: UNIX: 1. In the following script compileejb.sh, the actual J2EE is installed table of Contents.
#! / bin / sh
J2EE_HOME =
Cpath =.: $ J2EE_HOME / LIB / J2EE.JAR
Javac-ClassPath "$ CPATH" ConvertRejb.java Converterhome.java Converter.java
2. Run the compileejb.sh script Windows: 1. In the following CompileEJB.BAT batch file, you will be the actual J2EE installation directory.
Set J2EE_HOME =
Set cpath =.;% J2EE_HOME% / lib / j2ee.jar
Javac-ClassPath% cpath% converterejb.java converterhome.java converter.java
2. Run the batch file compileejb.bat.