Book Image

Java EE 7 Development with NetBeans 8

By : David R Heffelfinger
5 (1)
Book Image

Java EE 7 Development with NetBeans 8

5 (1)
By: David R Heffelfinger

Overview of this book

Table of Contents (18 chapters)
Java EE 7 Development with NetBeans 8
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Accessing the bean from a client


Now, it's time to focus our attention on the client. For remote clients, the client project needs to use the Java Class Library project containing the remote interface; this is the reason we created a Java Class Library project earlier in the chapter and added it to the client project.

After adding the client library containing the remote interface for our session bean, we are ready to invoke our EJB method. The client code needs to obtain a reference to an instance of a class implementing the remote interface for our bean. When using NetBeans, this is very easy. We simply need to right-click on the client code (com.ensode.sessionbeanintro.Main in the application client project in our example) and go to Insert Code... | Call Enterprise Bean.

At this point, we are shown a list of all open projects that have EJBs in them; we need to select the bean we wish to access from one of these projects.

If our bean had both a local and remote interface, we would have been...