7 Replies Latest reply on Mar 21, 2011 1:04 PM by bertoz84

    EJB - JBOSS - JNDI      HELP!!!

      Hello, i'm new!!!

       

      I'm approacing for the first time with JBoss and EJB; currently i'm running JBOSS 6.0 final, EJB 3.0 ( i chose this when i created my project - i don't want to use EJB 3.1 for now ), Eclipse Helios. Everything should be configured, i hope.

       

      That's what i have done till now:

       

      Created a CalculatorBean and his interface CalculatorRemote under the package mycalcBean;

      Created a CalculatorClient under the package mycalcClient;

       

      both in the same EJB project MyProjectEJB3.0.

       

      The client is a Java simple main that looks up for my bean and use a couple of his methods and runs as a Java application.

       

       

      I have to set environment properties in my client and pass env to my context.lookup:

       

                           Hashtable<String, String> env = new Hashtable<String, String>();

                           env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                           env.put(Context.PROVIDER_URL, "localhost:1099");

                           env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");

                           InitialContext ctx = new InitialContext(env);

                           Object obj = ctx.lookup(CalculatorBean.class.getSimpleName() + "/remote"/*"CalculatorBean/remote"*/);

       

      or i get the NOINITIALCONTEXT error.

      Why i need to do this when a lot of tutorials don't? Moreover i would prefer to use @EJB to look for my bean.

      I have read a lot of things that tell about the jndi.properties file. Well, that's my file under JBOSS_HOME\server\default\conf:

       

      # DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING

      #

      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

       

      I also tryed to put this file in the path where i have my client and in the CLASSPATH of my JDK.

       

      Nothing worked. Why my client can't read this default conf file?

       

       

       

       

       

      One last question:

      if i change position to my client, putting it into a different project ( for example: MyProjectEJB3.0Client ) the compiler doesn't see the import project.mycalcBean.*

      How to do that?

       

       

      thank you for your understanding and help!!!

        • 1. EJB - JBOSS - JNDI      HELP!!!
          wdfink

          First of all,

          how your JBoss is installed and how do you deploy your application?

          Do you see whether the application is correct started?

           

          And what error messages do you see at client side?

          • 2. Re: EJB - JBOSS - JNDI      HELP!!!

            downloaded JBOSS 6.0 final, unpacked it in C:\Jboss_releases.

            i run it directly inside Eclipse, but it works fine also launching it from the console ( p.s. i have WIN7 64bit ).

             

            I deploy my project right-clicking on it inside Eclipse, then Export->JAR file inside the Jboss\servers\default\deploy. It all works fine. If i launch my client with the env settings all works fine.

            If i exlude that i get:

            javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resourcefile: java.naming.factory.initial

             

            here's the solution http://community.jboss.org/wiki/GetquotjavaxnamingNoInitialContextExceptionquot but it doesn't work for me.

             

            I think the problem is that my client is not running on jboss server so it has a different JVM...this is what i understood by reading a lot of documents about JNDI.

             

            here is the console while starting server:

            ....................

            14:52:15,340 INFO  [JBossASKernel] Created KernelDeployment for: Calculator.jar

            14:52:15,344 INFO  [JBossASKernel] installing bean: jboss.j2ee:jar=Calculator.jar,name=CalculatorBean,service=EJB3

            14:52:15,344 INFO  [JBossASKernel]   with dependencies:

            14:52:15,344 INFO  [JBossASKernel]   and demands:

            14:52:15,344 INFO  [JBossASKernel]           jboss.ejb:service=EJBTimerService; Required: Described

            14:52:15,345 INFO  [JBossASKernel]           jboss-switchboard:appName=Calculator,module=Calculator,name=CalculatorBean; Required: Create

            14:52:15,345 INFO  [JBossASKernel]   and supplies:

            14:52:15,345 INFO  [JBossASKernel]           jndi:CalculatorBean/remote

            14:52:15,345 INFO  [JBossASKernel]           Class:project.sessionbean.CalculatorRemote

            14:52:15,346 INFO  [JBossASKernel]           jndi:CalculatorBean/remote-project.sessionbean.CalculatorRemote

            14:52:15,346 INFO  [JBossASKernel]           jndi:CalculatorBean

            14:52:15,349 INFO  [JBossASKernel] Added bean(jboss.j2ee:jar=Calculator.jar,name=CalculatorBean,service=EJB3) to KernelDeployment of: Calculator.jar

            14:52:15,429 INFO  [SessionSpecContainer] Starting jboss.j2ee:jar=Calculator.jar,name=CalculatorBean,service=EJB3

            14:52:15,437 INFO  [EJBContainer] STARTED EJB: project.sessionbean.CalculatorBean ejbName: CalculatorBean

            14:52:15,485 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

             

             

                      CalculatorBean/remote - EJB3.x Default Remote Business Interface

                      CalculatorBean/remote-project.sessionbean.CalculatorRemote - EJB3.x Remote Business Interface

            ....................

             

             

             

             

            p.p.s. i have also this warn:

            log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).

            log4j:WARN Please initialize the log4j system properly.

            • 3. EJB - JBOSS - JNDI      HELP!!!

              pls pls pls pls help!!!!

               

              • 4. EJB - JBOSS - JNDI      HELP!!!
                jaikiran

                stefano bertozzi wrote:

                 

                p.p.s. i have also this warn:

                log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).

                log4j:WARN Please initialize the log4j system properly.

                For this WARN message, you are missing a log4j.properties (or log4j.xml) in your client's (the program that runs in a different JVM) classpath.

                 

                 

                stefano bertozzi wrote:

                 

                downloaded JBOSS 6.0 final, unpacked it in C:\Jboss_releases.

                i run it directly inside Eclipse, but it works fine also launching it from the console ( p.s. i have WIN7 64bit ).

                 

                 

                If i exlude that i get:

                javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resourcefile: java.naming.factory.initial

                 

                This too is because of a missing jndi.properties in the client classpath. For both these issues, all you have to do is figure out how to set the classpath in Eclipse (assuming you are running the client program from Eclipse), for the client program, so that those files are picked up from the classpath.

                • 5. Re: EJB - JBOSS - JNDI      HELP!!!

                  thank you for help.

                   

                  I have no log4j.properties or .xml in my whole computer.

                  I saw that this log4j is something that you can download from APACHE, like ant ( ant also is missing in my JBOSS distribution; is it ant something that usually comes with jboss? ). I don't know if i need it.

                   

                   

                  CLASSPATH in my win7 is set to: .;C:\Program Files\Java\jre6\lib\ext\QTJava.zip

                   

                   

                  To see my project classpath in Eclipse i did this: Properties->Java Build Path->Source . Here i see that the default path is, obviously, myproject/ejbmodules. So i added my log4j and jndi files to this folder; that should overcome the visibility problem. But the error while launching my client is always the same, like the warn. So my java client still doesn't read these files.

                  • 6. Re: EJB - JBOSS - JNDI      HELP!!!
                    wdfink

                    stefano bertozzi schrieb:

                     

                    I have no log4j.properties or .xml in my whole computer.

                    Yes, that is exact the reason for the warning as Jaikiran mentioned before.

                    Create one for your client, see apache logging project for help how to do.

                    • 7. Re: EJB - JBOSS - JNDI      HELP!!!

                      I think that this IS the Graal of what's happening to my client:

                       

                      http://community.jboss.org/wiki/HowtouseanapplicationclientinJBoss-5

                       

                      If i understand well this article, it says that a Java Client doesn't see a lot of thing related to JBOSS ( that's why i can't do a lookup without create first an environment and i have the "misses the log4j file" warn ); so i should launch my client doing that "extremly long command" on command prompt.

                      So i guess that every tutorial on internet that doesn't create the environment can run their clients through Eclipse ( as i do ) because there's a way to set this "extremly long command" in it. If someone knows how to do it I would appreciate.

                       

                      I suppose that if i create many beans and use, lookup, etc...., them in a program that should run as an .ear on a server ( suppose the client can access my application through a browser and see a web page that uses session and entity beans ), i won't have to create the environment to lookup my beans. Am i right?

                       

                      I did this tutorial ( first part ):

                       

                      http://community.jboss.org/wiki/EJB31inAS600M2

                       

                      and i needed to add the env part only to lookup the AccountManager through the Client and not to lookup the Calculator through the AccountManager.

                       

                       

                       

                       

                       

                       

                      Another question:

                      I tryed to "Run on server" this tutorial; that's the console output:

                       

                      16:18:59,843 INFO  [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@1382208438{vfs:///C:/Users/Stefano/Documents/Eclipse/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.0_Runtime_1_Server1299168094927/deploy/CalculatorEJB3.1EAR.ear/CalculatorEJB3.1.jar/}

                      16:18:59,844 INFO  [org.jboss.ejb3.deployers.Ejb3DependenciesDeployer] Encountered deployment AbstractVFSDeploymentContext@1382208438{vfs:///C:/Users/Stefano/Documents/Eclipse/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_6.0_Runtime_1_Server1299168094927/deploy/CalculatorEJB3.1EAR.ear/CalculatorEJB3.1.jar/}

                      16:18:59,875 INFO  [org.jboss.ejb3.instantiator.deployer.BeanInstantiatorDeployerBase] Installed org.jboss.ejb3.instantiator.impl.Ejb31SpecBeanInstantiator@7e13674c into MC at org.jboss.ejb.bean.instantiator/CalculatorEJB3.1EAR/CalculatorEJB3.1/Calculator

                      16:18:59,875 INFO  [org.jboss.ejb3.instantiator.deployer.BeanInstantiatorDeployerBase] Installed org.jboss.ejb3.instantiator.impl.Ejb31SpecBeanInstantiator@7e13674c into MC at org.jboss.ejb.bean.instantiator/CalculatorEJB3.1EAR/CalculatorEJB3.1/AccountManagerBean

                      16:18:59,876 WARN  [org.jboss.ejb3.interceptor.InterceptorInfoRepository] EJBTHREE-1852: InterceptorInfoRepository is deprecated

                      16:18:59,942 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Created KernelDeployment for: CalculatorEJB3.1.jar

                      16:18:59,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:ear=CalculatorEJB3.1EAR.ear,jar=CalculatorEJB3.1.jar,name=AccountManagerBean,service=EJB3

                      16:18:59,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:

                      16:18:59,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:

                      16:18:59,943 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jboss-switchboard:appName=CalculatorEJB3.1EAR,module=CalculatorEJB3.1,name=AccountManagerBean; Required: Create

                      16:18:59,944 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jboss.ejb:service=EJBTimerService; Required: Described

                      16:18:59,944 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jboss-injector:topLevelUnit=CalculatorEJB3.1EAR.ear,unit=CalculatorEJB3.1.jar,bean=AccountManagerBean; Required: Described

                      16:18:59,944 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:

                      16:18:59,944 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jndi:CalculatorEJB3.1EAR/AccountManagerBean/remote-org.jboss.ejb3.example.AccountManager

                      16:18:59,944 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           Class:org.jboss.ejb3.example.AccountManager

                      16:18:59,944 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jndi:CalculatorEJB3.1EAR/AccountManagerBean/remote

                      16:18:59,945 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jndi:AccountManagerBean

                      16:18:59,945 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:ear=CalculatorEJB3.1EAR.ear,jar=CalculatorEJB3.1.jar,name=AccountManagerBean,service=EJB3) to KernelDeployment of: CalculatorEJB3.1.jar

                      16:18:59,953 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:ear=CalculatorEJB3.1EAR.ear,jar=CalculatorEJB3.1.jar,name=Calculator,service=EJB3

                      16:18:59,953 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:

                      16:18:59,953 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:

                      16:18:59,953 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jboss.ejb:service=EJBTimerService; Required: Described

                      16:18:59,953 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jboss-switchboard:appName=CalculatorEJB3.1EAR,module=CalculatorEJB3.1,name=Calculator; Required: Create

                      16:18:59,954 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:

                      16:18:59,954 INFO  [org.jboss.ejb3.deployers.JBossASKernel]           jndi:Calculator

                      16:18:59,955 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:ear=CalculatorEJB3.1EAR.ear,jar=CalculatorEJB3.1.jar,name=Calculator,service=EJB3) to KernelDeployment of: CalculatorEJB3.1.jar

                      16:19:00,004 INFO  [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=CalculatorEJB3.1EAR.ear,jar=CalculatorEJB3.1.jar,name=Calculator,service=EJB3

                      16:19:00,004 INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: org.jboss.ejb3.example.Calculator ejbName: Calculator

                      16:19:00,005 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                      16:19:00,005 WARN  [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers

                      16:19:00,042 INFO  [org.jboss.ejb3.nointerface.impl.jndi.AbstractNoInterfaceViewBinder] Binding the following entry in Global JNDI for bean:Calculator

                       

                                CalculatorEJB3.1EAR/Calculator/no-interface -> EJB3.1 no-interface view

                       

                      16:19:00,059 INFO  [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=CalculatorEJB3.1EAR.ear,jar=CalculatorEJB3.1.jar,name=AccountManagerBean,service=EJB3

                      16:19:00,060 INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: org.jboss.ejb3.example.AccountManagerBean ejbName: AccountManagerBean

                      16:19:00,066 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                       

                                CalculatorEJB3.1EAR/AccountManagerBean/remote - EJB3.x Default Remote Business Interface

                                CalculatorEJB3.1EAR/AccountManagerBean/remote-org.jboss.ejb3.example.AccountManager - EJB3.x Remote Business Interface

                       

                      16:19:00,067 WARN  [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers

                       

                       

                      It sounds good but it created a folder named CalculatorEJB3.1EAR.ear in the path: C:\Users\Stefano\Documents\Eclipse\.metadata\.plugins\org.jboss.ide.eclipse.as.core\JBoss_6.0_Runtime_1_Server1299168094927\deploy

                       

                      I expected to have a file CalculatorEJB3.1EAR.ear under my JBoss_distr\server\default\deploy. Is this the usual behaviour? If i run my client i got errors. If i export my project as a .jar under my JBoss_distr\server\default\deploy it works. How to create the .ear file containing my .jar and .war?

                       

                      that's what happens if i try to export my project ad .ear and place it inside jboss:

                      ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Real: name=vfs:///C:/JBoss_releases/jboss-6.0.0.Final/server/default/deploy/CalculatorEJB3.1EAR.ear state=PreReal mode=Manual requiredState=Real: org.jboss.deployers.spi.DeploymentException: Could not install bean instantiator

                       

                      Thank you for helping the biggest JBoss-noob ever, me!