i’m developing an application on top of netbeans API using Glassfish 3.1.2. My netbeans application is supposed to be my standalone java client that have to connect to the EJB.
I have packaged my EJB into an EAR (enterprise application). The problem i’m facing of is that i got an exception when i try to lookup for available EJBs.
Here is my bean session:
@Stateless
@EJB(name = "java:global/AltServer", beanInterface = AltServerRemote.class)
public class AltServer implements AltServerRemote {
The remote interface:
@Remote
public interface AltServerRemote {
And finally the lookup call:
props.setProperty("org.omg.CORBA.ORBInitialHost", getGlassfishHostname());
props.setProperty("org.omg.CORBA.ORBInitialPort", getServerPort());
ctx = new InitialContext(props)
ctx.lookup("java:global/AltServerEnt/AltServer-ejb/AltServer")
About how to lookup an EJB packaged into an EAR, i have followed this : http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#CosNaming and foud the jndi syntax:
java:global[/<app-name>]/<module-name>/<bean-name>
So in my case my enterprise application is AltServerEnt, my EJB module is AltServer-ejb and my session bean is called AltServer (see above).
Note: I have used the @EJB annotation to my session bean to specify a name like explained in FAQ i linked above, i’m not sure it’s suitable when the EJB is part of an EAR. Anyone know?
And here the exception i got, raised at the line of the lookup:
java.lang.ClassNotFoundException: com.sun.ejb.codegen.GenericEJBHome_Generated
There are a lot of “Caused” clauses but here is the first one:
javax.naming.NamingException: Lookup failed for 'java:global/AltServerEnt/AltServer-ejb/AltServer' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=127.0.0.1, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: ejb ref resolution error for remote business interfaceorg.altanis.remote.AltServerRemote [Root exception is java.lang.RuntimeException: Could not invoke defineClass!]]
So i guess my session bean is not found but why? My JNDI syntax isn’t right?
EDIT: Just to notice my project organization:
- AltServerEnt: Enterprise Application – contains the EJB module
- AltServer-ejb: EJB Module – contains the sessions bean and includes a netbeans plugin that contains the remote interface (AltServerRemote).
Thanks for reading.
The EAR/EJB apparently deployed. So bring up the Glassfish Admin console, something like
https://<host>:4848and login. On the left, navigate throughApplicationsand click on your application to bring up the ‘Edit Application’ screen. Examine Application’s name & Component names displayed – and compare to what your expectations are.I don’t have any remote EJBs deployed at the moment, so I can’t confirm – but I think that for remote EJBs there may be a link under the
Actioncolumn to display the URL.Naming Options
Use the name
AltServeras the EJB’s name:name="EJB(name = "AltServer" ...). With a "simple name", the bean can be found in various JNDI namespaces (global/app/module); your lookupctx.lookup("java:global/AltServerEnt/AltServer-ejb/AltServer")should work.If you add the prefix
java:globalthen you’ve declared a name directly in the JNDI global namespace; you would be able to lookup your bean directly in that namespace using the same name:java:global/AltServer. Yes, you should still be able to access it in other namespaces – see first paragraph.Also
You ask: "I have used the @EJB annotation to my session bean to specify a name like explained in FAQ i linked above, i’m not sure it’s suitable when the EJB is part of an EAR. Anyone know?"
It’s fine, it all depends on what you want. Like all name-spaces, one might think towards avoiding overpopulating a namespace – particularly the global namespace. Give it a few moments of thought, and just make a decision – and be ready to rethink it if needed 🙂