Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

EJB bites back

Thread view: 
sasuke - 08 Dec 2007 06:11 GMT
Hello all.

For the past few days I have been trying to understand the complicated
concept behind EJB 3 but to no avail. I even haven't been able to run
a sample 'Hello world' app using the Netbeans IDE. Here are a few
questions I have in mind:

◄ Do I have to package the entire j2ee.jar file and give it to the
client(desktop application) if they want to avail the services of the
EJB components deployed on my server. I ask this because when
programming the client we use the @EJB annotation to dynamically
locate and inject the EJB inside the EJB reference.

◄ I tried creating an 'Enterprise application' in Netbeans with the
EJB's in a package named "home.ejb" and the client program in the
package named "home.client" just so I can test and deploy my first ejb
but it gives me a NullPointerException when I do something like below.
Both the bean package and client package are in the same application.

public class Test {
   @EJB
   private static HelloRemote helloBean;

   public static void main(String args[]) {
       helloBean.sayHello(); //sayHello is the business method
   }
}

I guess my understanding of EJB concepts is really flawed or something
in my configuration is missing. Any help would be greatly appreciated.

Thanks,
--sasuke
Lew - 08 Dec 2007 06:31 GMT
> For the past few days I have been trying to understand the complicated
> concept behind EJB 3 but to no avail. I even haven't been able to run
[quoted text clipped - 6 lines]
> programming the client we use the @EJB annotation to dynamically
> locate and inject the EJB inside the EJB reference.

Quoting from <http://java.sun.com/javaee/5/docs/tutorial/doc/bnbls.html>
> Enterprise beans run in the EJB container, a runtime environment within
> the Application Server (see Container Types).

You need an app server like JBoss or GlassFish.

Signature

Lew

sasuke - 08 Dec 2007 06:44 GMT
> Quoting from <http://java.sun.com/javaee/5/docs/tutorial/doc/bnbls.html>
>
[quoted text clipped - 5 lines]
> --
> Lew

I am new to EJB but not that new to the general concepts. I do have a
App server (glassfish) up and running. It's admin console also shows
that the HelloBean is deployed on it but I can't get to run it or
access that bean from a client program.

Thanks,
--sasuke.
Lew - 08 Dec 2007 06:46 GMT
>> For the past few days I have been trying to understand the complicated
>> concept behind EJB 3 but to no avail. I even haven't been able to run
[quoted text clipped - 12 lines]
>
> You need an app server like JBoss or GlassFish.

Oh, you're trying to annotate the client side.

<http://java.sun.com/javaee/5/docs/tutorial/doc/bnbmg.html#bnbmh>
> To create an enterprise bean that allows remote access, you must do one of the following:
>
[quoted text clipped - 7 lines]
>       @Remote(InterfaceName.class)
>       public class BeanName implements InterfaceName { ... }

Now I'm reading
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnbnj.html>
for the client side.
>  the application client container injects the resource references at runtime.

It seems that besides JBoss and GlassFish (and WebLogic and WebSphere and
...), there is a little program from Sun called 'appclient' that will run the
client app.
<http://docs.sun.com/app/docs/doc/819-3675/appclient-1m?a=view>

I never knew that.  I always thought you needed an app server to run EJB
clients.  Turns out, not all containers are app servers.

Signature

Lew

EricF - 08 Dec 2007 06:39 GMT
>Hello all.
>
[quoted text clipped - 29 lines]
>Thanks,
>--sasuke

Yes, you are missing the point of injection. The container injects a reference
when using @EJB annotation. The client (unless the client is another EJB) does
not run within a container. An ejb client still needs to use jndi.

Eric
Lew - 08 Dec 2007 06:49 GMT
> Yes, you are missing the point of injection. The container injects a reference
> when using @EJB annotation. The client (unless the client is another EJB) does
> not run within a container. An ejb client still needs to use jndi [sic].

That information does not accord with the literature from Sun.  Sun's JEE
tutorial talks about using a container to run clients, as I mention upthread.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.