1 Reply Latest reply on Sep 17, 2015 11:44 AM by D P

    Remote invocation of EJB from clients in Wildfly

    Ramanan Kannan Newbie

      I am trying to invoke an ejb from a remote client. I am using the Wildfly 8.1 server. While running the client and trying to lookup the remote object, i am getting the below mentioned error.

      Code piece: 1

       

      public TicketAgencyClient() throws NamingException {

              final Properties jndiProperties = new Properties();

              jndiProperties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");       

              this.context = new InitialContext(jndiProperties);

          }

       

      [INFO] --- exec-maven-plugin:1.2.1:exec (default-cli) @ ticket-Agency-ejb-client ---

      Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)

          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)

          at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)

          at javax.naming.InitialContext.lookup(InitialContext.java:417)

          at com.packtpub.wflydevelopment.chapter3.client.TicketAgencyClient.lookupTheatreInfoEJB(TicketAgencyClient.java:115)

          at com.packtpub.wflydevelopment.chapter3.client.TicketAgencyClient.run(TicketAgencyClient.java:49)

          at com.packtpub.wflydevelopment.chapter3.client.TicketAgencyClient.main(TicketAgencyClient.java:19)

       

      If the initial context is added in the JNDI properties, then I am getting different errors.

       

      Code piece 2

      public TicketAgencyClient() throws NamingException {

             final Properties jndiProperties = new Properties();

              jndiProperties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");       

              jndiProperties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");       

              this.context = new InitialContext(jndiProperties);

          }

       

      Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory]

          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)

          at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)

          at javax.naming.InitialContext.init(InitialContext.java:244)

          at javax.naming.InitialContext.<init>(InitialContext.java:216)

          at com.packtpub.wflydevelopment.chapter3.client.TicketAgencyClient.<init>(TicketAgencyClient.java:34)

          at com.packtpub.wflydevelopment.chapter3.client.TicketAgencyClient.main(TicketAgencyClient.java:19)

      Caused by: java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory

          at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

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

          at java.lang.Class.forName(Class.java:348)

          at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)

          at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)

          at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)

          ... 5 more

       

      I am not sure of the extra changes required to do JNDI lookup and I am new to Java EE development. I am stuck with this for a while. Could any one suggest me to get out of this issue?

       

      Thanks in advance!

       

      - Ramanan K