You will need a Application Client Container (ACC) which will invoke that class. You can't use it as a normal standalone java class because the container is responsible for injecting the resources. I guess Glassfish provides a ACC and their documentation might contain more details.
You can call a EJB from a plain java class using JNDI lookup. However injecting the bean in that plain java class won't work because there will be no container which processes this plain java file for injecting the resource.
Jeffry Kristianto Yanuar
Ranch Hand
Joined: Oct 01, 2007
Posts: 759
posted
0
Does the plain java class must be run on the same PC which is the server is running ?
If we can do the lookup to JNDI server outside the PC which is the server is running, do we need the IP address of the server ?
Jeffry Kristianto Yanuar wrote:Does the plain java class must be run on the same PC which is the server is running ?
You can lookup a EJB located on a remote server. The client need not be on the same server.
Jeffry Kristianto Yanuar wrote:
If we can do the lookup to JNDI server outside the PC which is the server is running, do we need the IP address of the server ?
The JNDI lookup usually looks like this:
In this case a file named jndi.properties is searched in the classpath to determine the "context" information which includes the server address.
You can even pass the server address in the code itself through a Properties parameter to the InitialContext
Arun Kandregula wrote:
JNDI names are not yet standardized in portable fasion by EJB spec yet. So even default JNDI names vary from app server to app server.
Arun is right, the default JNDI names are app server specific. However, the EJB 3.1 spec will introduce a standard global JNDI naming scheme which will help standardize the default JNDI names.
subject: EJB3 Dependency Injection: How to write ApplicationClient injecting @EJB correctly ?