users@glassfish.java.net

Re: RE: Vista versus Pro (GlassFish/Eclipse) and EJB

From: <glassfish_at_javadesktop.org>
Date: Thu, 20 Aug 2009 14:29:50 PDT

Tan,

Ok, I used to have the same problems and it took me so long to fix it.
One way to fix this' to change the mapname for the other PC:

Bean

@Statelss(mappedName="TimerBean2")

in the client:

InitialContext ic = new InitialContext();
TimerBeanRemote timerBeanRemote = (TimerBeanRemote)ic.lookup("TimerBean2");


But this would be hard to manage because, you'd have to change it
everytime you've to deploy it to other servers.

Another way to fix such a problem is use @EJB. This' the best way.

In the main client(the first client that loads up)

Make a reference to your bean:

@EJB
private Bean bean;

Check this thread from:

"
Date: Mon, 13 Oct 2008 16:26:56 -0500
From: Timothy.Quinn_at_Sun.COM
To: ejb_at_glassfish.dev.java.net
CC: persistence_at_glassfish.dev.java.net
Subject: Re: injections

Eve,

It's important to note that the Java EE 5 spec specifies that injection take place only in "managed" classes. In the app client, there are only two managed classes: the main class (as specified either in the manifest or on the appclient command line) and the optional log-in callback class.

Also, the spec also mandates that in the app client main class only static elements can be injected.

Here is one general approach that some people find works for them:

1. Define the injected static fields on the app client's main class:

@EJB
private static UsersRemote usersRemote;

2. Write a static accessor method on the app client's main class:
static UserRemote getUserRemote() {
    return usersRemote;
}
3. From anywhere in any of the classes in your app client use Main.getUserRemote() when you need to use the EJB.

- Tim


"

I kept a copy of this thread because, it took me a very long time
to get someone like Tim to understand the problem I was facing.

Hope this helps.

eve
[Message sent by forum member 'eve2' (eve2)]

http://forums.java.net/jive/thread.jspa?messageID=361497