EJB bites back

S

sasuke

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
 
L

Lew

sasuke said:
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.

Quoting from said:
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.
 
E

EricF

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:

=E2=97=84 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.

=E2=97=84 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

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
 
S

sasuke

You need an app server like JBoss or GlassFish.

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.
 
L

Lew

Lew said:
You need an app server like JBoss or GlassFish.

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

To create an enterprise bean that allows remote access, you must do one of the following:

* Decorate the business interface of the enterprise bean with the @Remote annotation:

@Remote
public interface InterfaceName { ... }

* Decorate the bean class with @Remote, specifying the business interface or interfaces:

@Remote(InterfaceName.class)
public class BeanName implements InterfaceName { ... }

Now I'm reading
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.
 
L

Lew

EricF said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top