EJB3 Glassfish JNDI lookup

心已入冬 提交于 2019-12-05 09:16:15

Can you just add the above lines:

  Properties props = new Properties();
 props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
 props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
 // glassfish default port value will be 3700,
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ctx = new InitialContext(props);

 CalculatorRemote bean = (CalculatorRemote) ctx.lookup("java:global/TestEAR/TEjb/Calculator!    com.CalculatorRemote");

I have created a blog post here using EJB3x with Glassfish v3. http://anirbanchowdhury.wordpress.com/2012/06/07/ejb-3-application-in-glassfish-3x/

I think that exception is thrown because you didn't configure the initial context properly. Either create a jndi.properties file, or create a hash table with the properties and it send it to the constructor of IntialContext.

Creating EJB3 using Netbeans and Glassfish

Just today I had an issue with this. Your standalone client failed but it will work inside GF EJB container.

For client testing you need 2 things to make it work:

  1. from GlassFish_install_folder\glassfish\lib get javaee, gf-client and appserv-rt jars. the last one contains jndi.prop so you could use default c-tor InitialContext();
  2. from GlassFish_install_folder\glassfish\modules get all jars.

These jars need to be in your classpath. It is silly but I don`t know yet the minimum jars from 2) in order to make it work.

nihar m.

Solution is as below.

In the code below, You have to call a bean in another JVM Right ? For ex, your main class is in JRE and BEAN is in Glassfish JVM.


public class Main {

    public static void main(String[] args) throws Exception {        
        InitialContext ctx = new InitialContext();      
        CalculatorRemote bean = (CalculatorRemote) ctx.lookup("java:global/TestEAR/TEjb/Calculator!com.CalculatorRemote");
        bean.sayHello("Billy Bob");
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!