J2EE Application Development B.Ramamurthy 11/19/2018
Introduction We will show how to develop, deploy and run a simple client-server application that consists of a currency converter enterprise bean and two clients: a J2EE client and a web client that consists of a JSP page. 11/19/2018
The Setup Source code from http://java.sun.com/j2ee/download.html#tutorial Get the J2EE1.3 from http://java.sun.com/j2ee Get the “ant” build tool from Jakarta. This is similar to “make” utility of unix. Setup the environment variables: JAVA_HOME: location of J2SE installation J2EE_HOME: location of J2EE installation ANT_HOME: location of ant installation PATH : include “bin” directories of J2EE, J2SE and ant installation 11/19/2018
Starting the Server J2EE server is a web server, servlet server and also an application server. You start it by j2ee –verbose You stop the server by J2ee -stop 11/19/2018
Deployment Has two modes: command line and GUI interface. In the case of GUI tool you create an “ear” file and the drop the component modules into this “ear” (enterprise archive) file. In the case of command line you will make the components first and then assemble them into an “ear” file. To start a deploy tool deploytool 11/19/2018
Application source code An enterprise bean which represents the business logic of an application: Remote interface: defines the business methods that a client may call. Home interface: defines the methods to create, find or remove an enterprise bean. Enterprise bean class: implements the two interfaces and also callbacks for containers. Our application is called “converter”. Lets study the code representing these files. 11/19/2018
Compiling the Source code The compile targets for this tutorial are available in a file build.xml. You compile the “converter” java files by ant converter 11/19/2018
Packaging For this example, “ear” file will be: ConverterApp.ear This file will contain: EJB JAR file, Web client’s WAR file and Application clients JAR file/class file Deploytool helps in configuring and packaging each component. It automatically creates the deployment descriptor. 11/19/2018
Packaging the enterprise bean Add the classes that make the bean component: Converter.class, ConverterBean.class, ConverterHome.class to the “jar” Specify properties: bean type (session, entity, etc.), transactions etc. The deploytool has various tabs and support to specify these. 11/19/2018
Application Client Written in Java. Can run on any Java runtime (need not be J2EE). In this application client requires two JAR files: JAR file for the J2EE containing client’s deployment descriptor and its class files, and the second JAR files containing stub classes required at run time by the client. 11/19/2018
Application Client (contd.) and Web Client Basic tasks performed by the client of an enterprise bean: Locating the home interface Creating an enterprise bean instance Invoking a business method Deploytool: Creates client’s deployment descriptor Puts deployment descriptor and client code into a JAR file Add the JAR file to the applications ConverterApp.ear file We use JSP for this purpose: contains the same tasks as the application client plus web display elements. 11/19/2018
Deployment and Running the Clients JNDI: We also specify JNDI names using the deploytool. Tools deploy of the tool. http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Tools10.html runclient etc. to run from command line Webclient: http://<host>:8000/converter 11/19/2018