Accessing JNDI context from remote application client.
Hi,
I'm having a problem with using JNDI references such as @EJB and @Resource in my application client, though when the client has been written as stand-alone with build in server properties setting:
publicstatic Context getInitialContext ()
throws javax.naming.NamingException
{
Properties p =new Properties( );
p.put(/** server properties*/);
returnnew javax.naming.InitialContext(props);
}
it was working well.
I suppose the root of evel is that I shall put jndi.properties in client jar instead code above, but is there a possibility to avoid this? Can client automaticaly detect server from which it has been downloaded without rewriting jndi.properties for concrete server?
[1033 byte] By [
straivera] at [2007-11-27 6:37:19]

# 1
The idea behind an Application Client is that your client code be portable and that it run within a
Java EE container that is similar to the containers in which your server components run.
Resource access is a service that is provided by the container so that your code does not have to
worry about the details of bootstrapping a naming service.The whole point is that you *not*
put specific naming configuration properties in the code.
@EJB and @Resource only work for Application Clients. A plain stand-alone java client can't
benefit from the Java EE environment annotations since it's not running within an App Client
container.
You can find more about these topics in our EJB FAQ :
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#AppClientDef
ksaksa at 2007-7-12 18:05:40 >

# 2
Thanks for article, I've put my code to work, but got a new strange bug.
@EJB references work only if they are defined in application-client.xml with <injection-target> tag and only if they are in main class of application client!
Else i'm getting NullPointerException. What can be reason of such bug? Please, help!
PS sorry for maybe stupid question.
# 3
For Application Clients, only the main class may declare Java EE annotations.This is similar to the
server-side, where only certain managed classes (EJB bean classes, servlets, ...) support annotations.
As for the other error, there is no requirement that application-client.xml be used in addition to the
environment annotations themselves.The one difference in using annotations on Application Client
main classes is injected fields/method must be static. That's because the container performs
injection *before* calling main().
--ken
ksaksa at 2007-7-12 18:05:41 >
