Reputation: 41
I have a simple problem, I have a Stateless EJB bean running in Glassfish 4. I have a client, and I want to lookup for this ejb, and I simply cannot make the right name. How should I name these correctly to work?
I just got javax.naming.NamingException
, but I have no clue how to do it right.
I follow the java:global/[ear-name]/[jar-name]/[ejb-name]![fully-qualified-interface-name]
convention.
Here is the client:
...
public class Main {
public static void main(String[] args) {
Calculator calculator;
Context ctx = null;
try {
Properties environment = new Properties();
environment.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
environment.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
// Find the EJB with a JNDI lookup
ctx = new InitialContext(environment);
calculator = (Calculator)ctx.lookup(
"java:global/calculator-application/calculator-ejb/calcBean!eak.Calculator"
);
} catch(NamingException ex) {
ex.printStackTrace();
return;
}
...
}
}
Here are the annotations of my EJB component:
@Stateless(name="calcBean", mappedName="calc")
@Remote(Calculator.class)
public class CalculatorBean implements Calculator {
...
And I run what jndi names are in my Glassfish server:
C:\javaee\glassfish4\glassfish\bin>asadmin.bat list-jndi-entries
UserTransaction: com.sun.enterprise.transaction.startup.TransactionLifecycleServ
ice$2
ejb: com.sun.enterprise.naming.impl.TransientContext
java:global: com.sun.enterprise.naming.impl.TransientContext
calc__3_x_Internal_RemoteBusinessHome__: javax.naming.Reference
calc: javax.naming.Reference
jdbc: com.sun.enterprise.naming.impl.TransientContext
concurrent: com.sun.enterprise.naming.impl.TransientContext
com.sun.enterprise.container.common.spi.util.InjectionManager: com.sun.enterpris
e.container.common.impl.util.InjectionManagerImpl
jms: com.sun.enterprise.naming.impl.TransientContext
calc#eak.Calculator: javax.naming.Reference
Command list-jndi-entries executed successfully.
Upvotes: 4
Views: 1917
Reputation: 3956
You'r configuration looks valid to me. I tested your example and it worked just fine. Please make sure that the gf-client.jar
from glassfish4/glassfish/lib
is in your classpath. Please also confirm that your application, module and bean names are as you see in the Glassfish console. In my case JNDI lookup string java:global/ear-1.0-SNAPSHOT/my-ejb-jar-1.0-SNAPSHOT/calcBean!Echo
worked perfectly.
Upvotes: 2