9 Replies Latest reply on Oct 4, 2003 8:52 AM by jcorbin4607

    JNDI Error when Running EJB Client in Jboss3.2.2

    jcorbin4607

      I am getting the following error when I run my test client in JBOSS. I am using Eclipse 3.0m3 with the MyEclipseIDE (3.6.2). My project is successfully deployed as an EAR containing a single EJB module.

      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:640)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:280)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at com.test.TestClient.main(TestClient.java:30)

      I think it is a configuration problem, but for the life of me I cannot seem to figure out what it is. I've also included my client below.

      public class TestClient {

      public static void main( String[] args ) {
      try {
      InitialContext ctx = new InitialContext();
      Object oRef = ctx.lookup( TestBeanHome.JNDI_NAME );
      TestBeanHome home = (TestBeanHome)PortableRemoteObject.narrow(oRef, TestBeanHome.class);
      TestBean bean = home.create();
      bean.replaceWithRealBusinessMethod();
      } catch (NamingException ne) {
      ne.printStackTrace();
      } catch (CreateException ce){
      ce.printStackTrace();
      } catch (RemoteException re) {
      re.printStackTrace();
      }
      }
      }

        • 1. Re: JNDI Error when Running EJB Client in Jboss3.2.2

          What about the naming service, presumably you are using properties file to read the naming information .
          This is what Jboss uses in 3.2.xxx.

          InitialContext.INITIAL_CONTEXT_FACTORY,
          "org.jnp.interfaces.NamingContextFactory");
          props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

          Vishal.

          • 2. Re: JNDI Error when Running EJB Client in Jboss3.2.2

            Oops.. I missed out some bits in my previou posting.

            Hashtable props = new Hashtable();

            props.put(
            InitialContext.INITIAL_CONTEXT_FACTORY,
            "org.jnp.interfaces.NamingContextFactory");

            props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");

            InitialContext initialContext = new InitialContext(props);

            This is it.

            • 3. Re: JNDI Error when Running EJB Client in Jboss3.2.2
              jcorbin4607

              Hello,

              Thanks for the reply. I thought if you set the jndi setttings in the jndi.properties file located in the .../server/default/conf that you didn't have to specify the properties in that way.

              • 4. Re: JNDI Error when Running EJB Client in Jboss3.2.2

                Well thats what I meant when I say that use this configuration in properties file which will be jndi.properties file.
                Anyway u are right.

                Vishal.

                • 5. Re: JNDI Error when Running EJB Client in Jboss3.2.2
                  jcorbin4607

                  I have them set, but it still doesn't work. I wonder if it has to do with the integration of MyEclipseIDE and not so much JBOSS. I will try specifying the environment properties.

                  • 6. Re: JNDI Error when Running EJB Client in Jboss3.2.2
                    darranl

                    Never edit the file in .../server/default/conf, that file is used for JBoss internal configuration NOT the client configuration.

                    • 7. Re: JNDI Error when Running EJB Client in Jboss3.2.2
                      tsg26

                      Hello jcorbin4607,


                      To help you to determine whether JBOSS jndi known as JNP is working , try using telnet : telnet localhost 1099 to check whether you got any response in the form of some string if you are setting your jnp port to 1099

                      Secondly, try setting your classpath for your java client programme to include the jndi.properties from the conf directory if you do not want to hard code jndi lookup environment .You could make use of the hastable such as env=ctx.getEnvironment() to confirm you environment values.

                      The funny thing with the stand alone JNP lookup is that you need to include certain files under jboss/client path in order to look up the JNDI. Having said that , you are also required to set you classpath for your java client
                      programme to include quite a number of files under the jboss/lib too. For simplicity, like what I do was to inclue all the jar files under the client as well as the lib path as one does not like to keep on getting messages telling which class is not found or what class is missing.

                      Base on my expericence, I am still getting some messages like editor property not found under the eclipse console,eventhough the java client successfully performed what it was written to do, I have even posted the question to FAQ & datasource section, but just could not get any response .

                      I hope you would follow my advice to resolve your problem and let me know the result so that I could know for sure whether the solution is workable or not before I posted again to help Jboss newbie.



                      Thanks


                      • 8. Re: JNDI Error when Running EJB Client in Jboss3.2.2

                        > Oops.. I missed out some bits in my previou posting.
                        >
                        > Hashtable props = new Hashtable();
                        >
                        > props.put(
                        > InitialContext.INITIAL_CONTEXT_FACTORY,
                        > "org.jnp.interfaces.NamingContextFactory");
                        >
                        > props.put(InitialContext.PROVIDER_URL,
                        > "jnp://127.0.0.1:1099");
                        >
                        > InitialContext initialContext = new
                        > InitialContext(props);
                        >
                        > This is it.
                        >


                        Hello,
                        The error messages indicate that you have some problems with Context setting. Since I learnt the hard way, I normally follow the recommended steps religiously.

                        From your Context Setting, I can see that you have omitted one entry. That could be the cause of your problem:

                        Try to include this
                        env.put("java.naming.factory.url.pkgs","org.jboss.naming.jnp.interfaces");

                        Below is my settings that work for me:

                        Hashtable env = new Hashtable();
                        env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
                        env.put(Context.PROVIDER_URL,"192.168.0.6:1099");
                        env.put("jnp.discoveryPort", "192.168.0.6:1099");
                        env.put("java.naming.factory.url.pkgs","org.jboss.naming.jnp.interfaces");
                        //env.put("java.rmi.server.hostname","192.168.0.6");
                        //env.put("java.security.policy","C:/security/securityFile");
                        Context ctx = new InitialContext(env);

                        Someone in this thread, pointed a very good debugging test to see if rmi is bounded to 1099.
                        Try to telnet 127.0.0.1 1099 and see if you get anything back.

                        Thanks

                        • 9. Re: JNDI Error when Running EJB Client in Jboss3.2.2
                          jcorbin4607

                          I can get a stand alone client to connect to JBOSS and am able to lookup an EJB when I run everything outside my IDE environment. I know it is a configuration setup issue with my IDE (MyEclipseIDE) but just not sure. If anyone reading t his uses MyEclipseIDE (3.6.x) and is successfully using the JBOSS integration let me know. I would love to hear what they had to do to setup the environment from a client (jars) point of view.


                          Cheers