What should I call EJB to look for it correctly?

I have a simple problem, I have a Stateless EJB bean running in Glassfish 4. I have a client and I want to search for this ejb and I just can’t make the correct name. How should I name them correctly?

I just got it javax.naming.NamingException, but I have no idea how to do it right. I follow the agreement java:global/[ear-name]/[jar-name]/[ejb-name]![fully-qualified-interface-name].

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 jndi names on 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.
+4
source share
1 answer

you'r . , . , gf-client.jar glassfish4/glassfish/lib . , , , bean , Glassfish. JNDI java:global/ear-1.0-SNAPSHOT/my-ejb-jar-1.0-SNAPSHOT/calcBean!Echo .

enter image description here

+2

Source: https://habr.com/ru/post/1569241/


All Articles