12 Replies Latest reply on Jun 9, 2003 1:42 PM by softator

    javax.naming.NameNotFoundException

    pipo

      Hello,

      I try to run a simple example of helloworld EJB!
      When I compile my client I have got javax.naming.NameNotFoundException. And apparently the program can't find the org.jnp.server.NamingServer.

      I have seen in this forum sometimes we have to define the jndi inside the jboss.xml but I don't use it, is it a bad choice or not? (it's only to display "helloworld").

      Thank you for any help and your kind assistance


      Here is the code of my very simple client :

      ========client=========
      /*
      * TestJBOSS => => HelloWorlClient.java
      *
      * Created on 2 juin 2003
      */

      /**
      * @author default
      */
      import javax.naming.Context;
      import javax.naming.InitialContext;
      //import java.util.Hashtable;
      import java.util.Properties;

      public class HelloWorldClient {

      public static void main(String[] args) {


      Properties p = new Properties();
      p.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
      p.setProperty("java.naming.provider.url","localhost:1099");
      p.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
      p.list(System.out);
      /*Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.PROVIDER_URL, "localhost:1099");
      env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");*/

      try {

      Context ctx = new InitialContext(p);
      Object obj = ctx.lookup("HelloWorld");
      HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow( obj, HelloWorldHome.class);
      HelloWorld helloWorld = home.create();
      System.out.println(helloWorld.hello());
      helloWorld.remove();

      } catch (Exception e) {

      e.printStackTrace();
      System.out.println("Exception: " + e.getMessage());

      }
      }
      }
      ========end of client==========

      ======ejb-jar.xml=============
      <?xml version="1.0" ?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_2_0.dtd">


      <ejb-jar>

      <enterprise-beans>
      JBoss Hello World Application
      <display-name>Hello World EJB</display-name>




      <ejb-name>HelloWorld</ejb-name>
      TestJBOSS.HelloWorldHome
      TestJBOSS.HelloWorld
      <ejb-class>TestJBOSS.HelloWorldBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>



      </enterprise-beans>

      </ejb-jar>
      =============================

        • 1. Re: javax.naming.NameNotFoundException

          have you the jboss-client.jar in the classpath of your client? (see the client directory in the JBoss release)

          • 2. Re: javax.naming.NameNotFoundException
            pipo

            Yes I have added the following file in my classpath:
            jboss-common-client.jar
            jboss-system-client.jar
            jboss-client.jar
            jbosssx-client.jar
            jnp-client.jar
            and my HelloWorld.jar

            But When I deploy my EJB Have got only this two lines displayed in the server console:
            jboss-common-client.jar

            16:24:14,734 INFO [MainDeployer] Starting deployment of package: file:/C:/Java/
            jboss-3.2.1_tomcat-4.1.24/server/default/deploy/HelloWorld.jar
            16:24:14,765 INFO [MainDeployer] Deployed package: file:/C:/Java/jboss-3.2.1_to
            mcat-4.1.24/server/default/deploy/HelloWorld.jar

            Nothing show me that the HelloWorld been created, deployed and started.
            And in the JNDI view service of JBoss nothing refers to my EJB HelloWorld.

            I am using JBOSS 3.2.1 and Eclipse 2.1


            Thank you

            • 3. Re: javax.naming.NameNotFoundException

              Bah your EJB seems to be deployed ;)

              go to http://localhost:8080/jmx-console (replace localhost by the machine where JBoss is running)

              and seach for your HelloWorld bean. Check that the JNDI name is correct.

              If you have a no class deffound on the jndp interfaces, this is definitely a classpath problem.

              • 4. Re: javax.naming.NameNotFoundException
                pipo

                hello,

                Impossible to found my HelloWorld bean in the jmx-console.
                I tried to see in service= jndiview but nothing apart Ejb Module: ejb-management.jar
                Maybe I don't look in the good place.
                I am a little lost in there.

                • 5. Re: javax.naming.NameNotFoundException

                  show your HelloWorld.jar (attach files)

                  • 6. Re: javax.naming.NameNotFoundException
                    pipo

                    here it is

                    • 7. Re: javax.naming.NameNotFoundException

                      uh? How did you generate this :D

                      It's completely wrong !!!

                      your classes should be in the root of the JAR according the package (let's say com.foo packagethen you should have directory com, directory foo inside com and your classes in foo)

                      A package has *never* upper case characters (JBossTEST is not valid)

                      Try to read 10 times the tutorial or maybe use some cool tools like XDoclet

                      But in any case it will deploy in JBoss. I don't understand why it does not complain by the way

                      • 8. Re: javax.naming.NameNotFoundException

                        Uh now I understand, there is no ejb-jar, no jboss.xml in the META-INF directory ;)

                        • 9. Re: javax.naming.NameNotFoundException
                          pipo

                          hello,

                          I have done exactly as you said to me yesterday except I have just create one package so now it is like this:
                          -test
                          -META-INF
                          ejb-jar.xml
                          jBoss.xml
                          HelloWorld.jar
                          HelloWord.java
                          HelloWorld.class
                          HelloWordHome.java
                          HelloWorldHome.class
                          HelloWordClient.java
                          HelloWorldClient.class
                          HelloWordBean.java
                          HelloWorldBean.class

                          But When I deploy this time Jboss is not happy I ve got the following error:

                          09:54:03,109 INFO [MainDeployer] Starting deployment of package: file:/C:/Java/
                          jboss-3.2.1_tomcat-4.1.24/server/default/deploy/HelloWorld.jar
                          09:54:04,859 ERROR [MainDeployer] could not create deployment: file:/C:/Java/jbo
                          ss-3.2.1_tomcat-4.1.24/server/default/deploy/HelloWorld.jar
                          org.jboss.deployment.DeploymentException: Unknown PUBLIC id in ejb-jar.xml: -//S
                          UN Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN
                          at org.jboss.metadata.ApplicationMetaData.importEjbJarXml(ApplicationMet
                          aData.java:232)
                          at org.jboss.metadata.XmlFileLoader.load(XmlFileLoader.java:141)
                          at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:433)
                          at org.jboss.deployment.MainDeployer.create(MainDeployer.java:784)
                          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:639)
                          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:613)
                          at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                          sorImpl.java:25)
                          at java.lang.reflect.Method.invoke(Method.java:324)
                          at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                          nDispatcher.java:284)
                          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
                          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                          at $Proxy7.deploy(Unknown Source)
                          at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymen
                          tScanner.java:302)
                          at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentS
                          canner.java:476)
                          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
                          doScan(AbstractDeploymentScanner.java:200)
                          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
                          loop(AbstractDeploymentScanner.java:211)
                          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
                          run(AbstractDeploymentScanner.java:190)
                          09:54:04,859 ERROR [URLDeploymentScanner] Failed to deploy: org.jboss.deployment
                          .scanner.URLDeploymentScanner$DeployedURL@8ed79a62{ url=file:/C:/Java/jboss-3.2.
                          1_tomcat-4.1.24/server/default/deploy/HelloWorld.jar, deployedLastModified=0 }
                          org.jboss.deployment.DeploymentException: Unknown PUBLIC id in ejb-jar.xml: -//S
                          UN Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN
                          at org.jboss.metadata.ApplicationMetaData.importEjbJarXml(ApplicationMet
                          aData.java:232)
                          at org.jboss.metadata.XmlFileLoader.load(XmlFileLoader.java:141)
                          at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:433)
                          at org.jboss.deployment.MainDeployer.create(MainDeployer.java:784)
                          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:639)
                          at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:613)
                          at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
                          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
                          sorImpl.java:25)
                          at java.lang.reflect.Method.invoke(Method.java:324)
                          at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
                          nDispatcher.java:284)
                          at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549)
                          at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
                          at $Proxy7.deploy(Unknown Source)
                          at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymen
                          tScanner.java:302)
                          at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentS
                          canner.java:476)
                          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
                          doScan(AbstractDeploymentScanner.java:200)
                          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
                          loop(AbstractDeploymentScanner.java:211)
                          at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.
                          run(AbstractDeploymentScanner.java:190)

                          I have read several times the tutorial but it seems wrong as it is indicate to put the META-INF folder not at the place you told me.

                          But my Meta-INF is always empty??



                          • 10. Re: javax.naming.NameNotFoundException

                            What I told you maybe quite not clearly is the following ;)

                            Here is the root of your JAR file

                            - META-INF
                            jboss.xml
                            ejb-jar.xml

                            - com
                            - foo
                            HelloWorld.class
                            HelloWorldHome.class
                            ....etc


                            in HelloWorld.java you should have something like

                            package com.foo; if not simply upgrade the directory structure

                            Validate also the ejb-jar.xml and the jboss.xml that your are building (against its DTD)

                            • 11. Re: javax.naming.NameNotFoundException
                              pipo

                              YES it was a misunderstanding from me ;)
                              Thank you for your time
                              Now my EJB is deployed correctly :D

                              But I have got another problem when I use my Client the compilation os OK but when I run I have got this error

                              java.lang.NoClassDefFoundError: Lorg/jboss/tm/TransactionPropagationContextFactory;

                              I dont' wan tbothe ryou with all that so I am going to post it in the beginner corner ;)

                              • 12. Re: javax.naming.NameNotFoundException
                                softator

                                Hi,

                                try to add the Boss\server\default\lib\jboss-transaction.jar file to your Java Build Path

                                Regards !