Prev | Next | J2EETM Developer's Guide
Clients |
program locates an enterprise bean with the following call:
TheObject objref = initial.lookup("java:comp/env/ejb/SimpleConverter");
ejb/SimpleConverter
string is the name by which the J2EEClient
code refers to the enterprise bean. This name does not have to be identical to the JNDI name of the enterprise bean in the deployed application. For example, the enterprise bean's JNDI name might be MyConverter
. In this case, you would map ejb/SimpleConverter,
the name coded in the client, to MyConverter
, the JNDI name of the enterprise bean. (A later section "Specifying the JNDI Name", shows you how to map the names with the Application Deployment Tool.)
Although this mapping adds a level of indirection, it provides a major benefit to distributed applications: Clients may use different names to refer to the same enterprise bean. The J2EEClient
code, for example, uses the SimpleConverter
name, but another client might refer to the same bean as CurrencyConverter
. Even if you changed the bean's JNDI name (MyConverter
) on the server, you wouldn't have to change the client's source code. But you would have to map the names again and re-deploy the application.
A stand-alone Java application client (such as ConverterClient
), also locates an enterprise bean by calling the JNDI lookup
method. However, the name coded in the stand-alone client must be identical to the bean's JNDI name on the server. You cannot map the two names in the Application Deployment Tool.
. The application contains the session bean documented in the Getting Started chapter. The source code required by the application resides in the doc/guides/ejb/examples/converter
subdirectory. Before stepping through the instructions in the next section, you should prepare the application:
ConverterApp
.
class. MyConverter
.
program.a. Read this explanatory text for an overview of the wizard's features.
b. Click Next.General Dialog Box:
a. Click the Add button next to the Contents text area.
b. In the dialog box titled "Add files to JAR," choose the directory containing theJ2EEClient.class
file (examples/converter
). You may either type the directory name in the Root Directory field or locate it by clicking Browse.
c. Select the J2EEClient.class
file from the text area and click Add.
d. Click OK.
e. In the Display Name field, enter MyConverterClient
.
f. Click Next.Enterprise Bean References Dialog Box:
a. Click Add.
b. In the Coded Name column enter ejb/SimpleConverter
.
c. In the Type column select Session
.
d. In the Home column enter ConverterHome
.
e. In the Remote column enter Converter
.
f. Click Finish.
ConverterApp
application, the JNDI name of the ConverterBean
is MyConverter
. But the J2EEClient
program refers to the same enterprise bean as SimpleConverter
. Therefore, you must map the SimpleConverter
name to MyConverter
:
1. In the tree view, select the ConverterApp
application.
2. In the JNDI Names tabbed pane perform these steps:
a. Verify that theConverterBean
component has theMyConverter
JNDI name.
b. For theejb/SimpleConverter
reference, enterMyConverter
for the JNDI name.
2. In the first dialog box, select the checkbox labelled "Return Client Jar."
3. In the text field that appears, enter the full path name for the file ConverterAppClient.jar
.
J2EEClient
program , enter this command:
Therunclient -client ConverterApp.ear -name MyConverterClient
ConverterApp.ear
file contains the J2EE application. The MyConverterClient
option is the display name of the J2EE application client component.
The client container pops open a login window. In the User Name field enter guest
and in the Password field enter guest123
. (These entries are the default values specified in the config/auth.properties
file.)
If the J2EE application client does not reside on the same host as the J2EE server, you should follow these steps:
1. Copy the ConverterAppClient.jar
file to the client host machine. Created during deployment, the ConverterAppClient.jar
file contains stub classes that enable remote connectivity.
2. Copy the ConverterApp.ear
file to the client host machine.
3. Set the APPCPATH environment variable to the fully qualified name of the .jar file. In the following example, the fully qualified name is /user/duke/ConverterAppClient.jar
:
UNIX, Bourne and Korn shells:setenv APPCPATH /user/duke/ConverterAppClient.jar
Windows:APPCPATH=/user/duke/ConverterAppClient.jar export APPCPATH
4. Set the VMARGS environment variable to theset APPCPATH=\user\duke\ConverterAppClient.jar
-Dorg.omg.CORBA.ORBInitialHost
option. In the following example, the option points to the remote host named buzz, where the J2EE server is running:
UNIX, Bourne and Korn shells:setenv VMARGS -Dorg.omg.CORBA.ORBInitialHost=buzz
Windows:VMARGS="-Dorg.omg.CORBA.ORBInitialHost=buzz" export VMARGS
5. Run theset VMARGS=-Dorg.omg.CORBA.ORBInitialHost=buzz
runclient
script:
runclient -client ConverterApp.ear -name MyConverterClient