The use and deployment of the logical name of JNDI in EJB

xiaoxiao2021-03-06  40

JNDI logical names often specify JNDI names directly in practical applications, because the benefits of this use are: avoiding the same JNDI name when deploying an EJB app and to modify the JNDI name specified in the program. (To give a simple example: If there is no logical name, deploy an EJB application to another EJB server, if you have a deployment, you must modify the program file, so In order to avoid deploying the EJB application, the same name JNDI name is needed, only need to use the JNDI name in the program to deploy the actual JNDI name and all OK.) This article is simple to apply << EJB stateless session bean simple application - Learning and Practice >> Description Use of JNDI's logical names and some differences and benefits of the previous example.

Simply change a piece of code in the client program to CalculatorClient.java and use the original documents: Calculator.java CalculatorHome.java Calculatorejb.java CalculatorClient.java

/ * @ Inbergondate 2004/9 / 8file name: CalculatorClient.java * /

Import java.awt. *; import java.awt.event. *; import javax.swing. *; import javax.naming. *; import javax.rmi. *;

public class CalculatorClient extends JFrame {public static int w = 500; public static int h = 95; public static String str = "Earnest Bank Welcomes You"; Container c; JLabel l, result; JTextField t; JButton b; public static String value Public statune DBL; Public Static Double Amt; Public CalculatorClient () {Super (STR); C = getContentPane (); C.SetLayout (New GridLayout (2, 2, 2, 2)); l = new jlabel (" ENTER THE AMOUNT IN DOLLARS ($) "); C.Add (L); T = New JtextField (10); C.Add (T); B = New JButton (" Calculate "); C.ADD (B); Result = new jlabel (); c.add (result); B.AddActionListener (new addevent ()); setsize (w, h); show ();} class addevent imports actionListener {public void actionPerformed (ActionEvent E) {Value = TgetText (); dbl = double.parsedouble (value); try {context IC = new initialContext (); object obj = Ic.lookup ("java: comp / env / localjndi); CalculatorHome Home = (CalculatorHome) PortableRemoteob JECT.NARROW (Obj, CalculatorHome.class); Calculator Calc = Home.create (); AMT = Calc.dollartors (DBL); Calc.Remove (); Calculator Calc2 = Home.create (); if (Calc2.isident " Calc)) {system.out.println ("Two pile facts points to the same remote home instance! ");} Else {system.out.println (" Did not point to the same remote home instance! ");} Result.setText (" Result (RS.) String.Valueof (AMT));} catch (Exception T ) {System.out.println (t);}}} public static void main (String args []) {new CalculatorClient ();

} Compilation redeployment

This example uses J2EE1.3e: / public_html / public_java / ap3> start j2ee -verbose: / public_html / public_java / ap3> deploytool first according to << EJB's stateless session bean simple application - Learning and Practice >> Deploy EJB This example The application container is AP3 and deployed the application: 1. Select the application container in this case as an example of the AP3 as an example file-> new-> Application Client, New Application Client

Wizard-Introduction dialog ---> next appears New Application Client Wizard dialog Add CalculatorClient $ addEvent.class CalculatorClient.class -> OK-> Next At this time new application

Client Wizard-General Dialog Select CalculatorClient in Main Class of Applicatoin Client.

DISPLIY NAME Covered in CalculatorClient-> Next-> Next-> Next-> Next-> Next-> Finished At this point in the AP3 container

CalculatorClient app appears. 2. Deployment Specifies JNDI Name Select App AP3 Select JNDI Name in the FILES.APPLICATIONS.AP3 dialog box to specify JNDI Name, as ap3jndi (this name is actual JNDI name) in Application. Select EJB in Files.AppClications.ap3.calculatorClient dialog box

Refs In EJB's Reference In Click Add Localjndi in CODENAME (the logical name specified in CalculatorClient.java) Enter the HOME interface in Home Interface: CalculatorHome Enter Local / Remote Interface in Local / Remote Interface

Port: Calculator Then return to select the reference name in the References dialog in this point (for just now

Localjndi) only needs to enter ap3jndi in JNDI Name, and correspond to the actual JNDI name, and in turn, select the AP3 container.

CalculatorClient's later JNDI Name on Deployment Settings for Localjndi is already ap3jndi. 4. Arrange and return to the JAR file Tools-> Deploy ..-> Select Return Client JAR Specify JAR File Path and Name (Use by default here) -> Next-> Next-

Finished-> OK5. When running an instance runtime program, you may let the input access to the EJB permission dialog, so before running Tools-> Server Configreation Select the username and password under the JSEE Server View Username and Password here.

Set classpath =% classpath%; ap3client.jarrunclient -client ap3.ear -name CalculatorClient (Runclient -client file name. pear -name customer program name) Enter the username and password entered in login for User to see << EJB's stateless Session Bean Simple Apply - Learning and Practice >> Execution Results If you will see the following login and help information in the console, INITIATING login ... binding name: `java: comp / env / localjndi` Two pile facts pointing to the same A remote home instance! If you have any questions, please contact me. . . INBER_NET@hotmail.com

转载请注明原文地址:https://www.9cbs.com/read-118365.html

New Post(0)