In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "how to create a J2EE application client". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The J2EE application client is written in JavaTM language. At run time, the client program and J2EE SERVER execute in different virtual machines (VM).
In this example, the J2EE application client needs two different JAR files. The first JAR file is the J2EE component of the client. This JAR file contains the client's deployment descriptor and its class files. When you run New Application Client wizard,deploytool, automatically create the JAR file and save it to the application's EAR file. JAR files defined by the J2EE specification can easily span all J2EE-compliant servers.
The second JAR file contains the stub classes necessary for the client program to run. These stub classes enable clients to access enterprise beans. Exe, which runs on J2EE server. Because this second JAR file is not covered by the J2EE Specifications, it is implementation-specific, intended only for the J2EE SDK.
The client source code of the J2EE application is in examples/src/EJB/converter/ConverterClient.java. In this chapter, you have compiled it along with the enterprise bean code, compiling the source files.
Write J2EE application client
The ConverterClient.java source code illustrates the basic tasks performed by the client of enterprise bean:
Positioning home interface
Create an enterprise bean instance
Invoke business methods
Positioning Home Interface
The ConverterHome interface defines a method with a lifecycle like create. Before ConverterClient can call the create method, it must instantiate an object of type ConverterHome. It is divided into three steps:
Create JNDI naming context.
Context initial = new InitialContext ()
Gets the object bound to ejb/SimpleConverter.
Object objref = initial.lookup ("java:comp/env/ejb/SimpleConverter")
Narrow the reference to a ConverterHome object.
ConverterHome home = (ConverterHome) PortableRemoteObject.narrow (objref, ConverterHome.class)
Create an instance of Enterprise Bean
To create an bean instance, the client calls the create method in ConverterHome and returns an object of type Converter. The remote Converter interface defines the business methods in bean that the client can call. When the client calls the create method, the EJB container instantiates (instantiates) bean and then calls the ConverterBean.ejbCreate method. The client calls the create method as follows:
Converter currencyConverter = home.create ()
Invoke business methods
It's easy to call a business method-- you just call a method on a Converter object. The EJB container will call the corresponding method on the ConverterEJB instance running on the server side. The following line of code is that the client invokes the business method on dollarToYen.
Double amount = currencyConverter.dollarToYen (100.00)
ConverterClient source code
The complete ConverterClient source code is as follows.
Import javax.naming.Context; import javax.naming.InitialContext; import javax.Rmi.PortableRemoteObject; import Converter; import ConverterHome; public class ConverterClient {public static void main (String [] args) {try {Context initial = new InitialContext (); Object objref = initial.lookup ("java:comp/env/ejb/SimpleConverter"); ConverterHome home = (ConverterHome) PortableRemoteObject.narrow (objref, ConverterHome.class); Converter currencyConverter = home.create (); double amount = currencyConverter.dollarToYen (100.00); System.out.println (String.valueOf (amount)) Amount = currencyConverter.yenToEuro (100.00); System.out.println (String.valueOf (amount)); currencyConverter.remove ();} catch (Exception ex) {System.err.println ("Caught an unexpected exception!"); ex.printStackTrace ();}
Compile the application client
The application client file and the enterprise bean file are compiled at the same time, as described in the compiled source file.
Package the J2EE application client
To package the application client components, you need to run deploytool's New Application Client Wizard. In this process, the wizard compiles the client file into a JAR file and adds the JAR file to the application's ConverterApp.ear file.
Start New Application Client Wizard and select File- > New Application Client. The wizard displays the following dialog box.
Introduction dialog box:
Read the instructions for an overview of the wizard's features.
Click Next.
JAR File Contents dialog box
In this combo box, select ConverterApp.
Click Edit.
In the Available Files directory tree, navigate to the examples/build/ejb/converter directory.
Select the ConverterClient.class file file and click Add.
Click OK.
Click Next.
General dialog box:
In the Main Class combo box, select ConverterClient.
Verify that the content of the Display Name column is ConverterClient.
In the Callback Handler Class combo box, select container-managed authentication.
Click Next.
Click Finish.
Specify the Enterprise Bean Reference of the application client
When the lookup method is called, ConverterClient references an enterprise bean:
Object objref = initial.lookup ("java:comp/env/ejb/SimpleConverter")
Specify reference as follows:
In the tree directory, select ConverterClient.
Select EJB Ref's tab.
Click Add.
Enter ejb/SimpleConverter. Coded Name in the column.
In the Type column, select Session.
In the Interfaces column, select Remote.
Enter ConverterHome. Home in the column.
Enter Converter. Remote in the column.
That's all for "how to create a J2EE application client". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.