0 Replies Latest reply on May 24, 2016 3:50 PM by Amandeep Singh Ghai

    Problems with EJB JNDI Lookup within JBoss itself

    Amandeep Singh Ghai Newbie

      I have created an EAR with 2 EJB JARs and 1 application client & deployed it to JBoss AS 7.1. The aim is to be able to invoke business methods defined in EJBs using their Local / Remote interface. I am trying JNDI Lookup using jboss-as-naming-7.1.1.final.jar, but it fails. I give the code snippet & error message below. I have added this jar in the build-path already.

       

      public class Main {

        public static void main(String[] args) throws Exception {

        Hashtable jndiProps = new Hashtable();

        jndiProps.put("java.naming.factory.initial", "org.jboss.as.naming.InitialContext");

        Context lCtx = new InitialContext(jndiProps);

        checkCalculatorBeanRemote lBean = (checkCalculatorBeanRemote)

        lCtx.lookup("java:global/BackendService/CalculatorEJB/checkCalculatorBean!test.calculator.checkCalculatorBeanRemote");

        System.out.println("Sum............" + lBean.checkCalWithJNDI());

        }

        public Main() {

        super();

        }

      }


      WARN: JBAS011801: Failed to set ObjectFactoryBuilder

      java.lang.NoClassDefFoundError: org/jboss/msc/service/ServiceRegistry

        at org.jboss.as.naming.NamingContext.<clinit>(NamingContext.java:80)

        at java.lang.Class.forName0(Native Method)

        at java.lang.Class.forName(Unknown Source)

        at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)

        at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)

        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

        at javax.naming.InitialContext.init(Unknown Source)

        at javax.naming.InitialContext.<init>(Unknown Source)

        at Main.main(Main.java:17)

      Caused by: java.lang.ClassNotFoundException: org.jboss.msc.service.ServiceRegistry

        at java.net.URLClassLoader$1.run(Unknown Source)

        at java.net.URLClassLoader$1.run(Unknown Source)

        at java.security.AccessController.doPrivileged(Native Method)

        at java.net.URLClassLoader.findClass(Unknown Source)

        at java.lang.ClassLoader.loadClass(Unknown Source)

        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

        at java.lang.ClassLoader.loadClass(Unknown Source)

        ... 10 more

       

       

      Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.as.naming.InitialContext [Root exception is java.lang.InstantiationException: org.jboss.as.naming.InitialContext]

        at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

        at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

        at javax.naming.InitialContext.init(Unknown Source)

        at javax.naming.InitialContext.<init>(Unknown Source)

        at Main.main(Main.java:17)

      Caused by: java.lang.InstantiationException: org.jboss.as.naming.InitialContext

        at java.lang.Class.newInstance(Unknown Source)

        ... 5 more

       

       

      Please advise further!