J2ee| programming in order to help domestic beginners, Java EE part of the document compiled, expect to be able to help the vast number of java-based enthusiasts.
This article will use a simple example to describe how to develop, deploy, and run a client/server application using EJBS. The example client is run as a Java standalone application, implemented by the Converterclient.java class. It implements a simple real-time session, mainly through the client application call server-side EJB class Converterejb.java to achieve. If you already have Java EE installed, you can find these examples in the Doc/guides/ejb/examples/converter directory.
To implement the simple example described in this article, you need to complete the following tasks:
• Writing and compiling EJB programs
• Create Java EE application
• Package EJB (. jar)
• Deploy Java EE application
• Writing and compiling client programs
• Run Client
In the following sections, we will briefly explain the above tasks and the knowledge points involved.
Premise
The prerequisite for implementing this article is that you have installed the J2SE SDK downloaded by the javasoft.com or related operating system vendor Web site, as well as the Java EE SDK (www.javasoft.com download) with the corresponding operating system version installed and configured correctly. For installation, configuration, and other further information on J2SE and Java EE, please refer to the product documentation.
EJB encoding
Each EJB program must require the following code to be written:
The remote interface defines the business methods that clients can invoke, which are implemented by the server-side enterprise components, and the Converter.java code involved in this article is as follows:
Import javax.ejb.ejbobject;//to introduce the necessary packages
Import java.rmi.RemoteException;
Public interface Converter extends Ejbobject {//must inherit Ejbobject class
/* Define a method that the client can invoke/*
Public double Dollartoyen (double dollars) throws remoteexception;
Public double Yentoeuro (double yen) throws remoteexception;
}
Local interface encoding
The local interface defines the method by which the client creates, locates, or moves the EJB, and the local interface class Converterhome interface in this article defines only a create method, which returns the remote interface type, encoded as follows:
The Enterprise Component (EJB) in this article is a stateless session component, Named Converterejb.java, the component implements two business methods: Dollartoyen and Yentoeuro, consistent with the client-accessible method defined by the remote interface converter, which is encoded as follows:
public class CONVERTEREJB implements 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 EJB
It is now necessary to compile the three classes above, with a slightly different compilation on the UNIX platform and the Nt/9x platform, compiled as follows:
Unix:
1. In the following script compileejb.sh, it will be the actual Java EE installation directory.
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.