4 Replies Latest reply on Dec 6, 2011 9:31 PM by jaikiran

    jndi.properties files is not read

    snavarro89

      Hello everyone,

       

      Im starting to develop with JBoss, and got stuck while trying to create my first application.

      Im running JBoss 7.0, maven 3.0.3, Eclipse Indigo 3.7

       

      So, I started with a Hello World Project just to test if my setup was correct, and it worked, I succesfully deployed the project and acces it through a web page.

      Then I tried to create a Hello World from my own, but this time I wanted to access my bean from a client application. So I deployed another bean to the server, so far so good, but then I created another project to create a test client application, and I got the following error

       

      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

       

      So I start searching in the web and read a lot of forums (before posting a question that surely was previously asked) and everyone said the same, I needed to add a jndi.properties file to my classpath, so I did, and the error still appeared, then I followed a basic tutorial for  stateless session beans, and did as the tutorial specified, which was the same as I was doing, but insted the client application class, was in the same project, I added the jndi file and the error was still coming up.

      I have the following structure

      SampleEJBProject

        -ejbModule

           -com.code.project

               -XXX.java

               -YYY.java

               -jndi.properties

       

      This is how I have the file configured

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

      java.naming.provider.url=localhost:1099  (already tried with jpn:// at the beginning)

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

       

      I searched on how could I be sure that my file was being used and found

      loader.getResources("jndi.properties")

      Which returns null.

       

      Ive already places the jdni.properties file in the root folder of the classpath and it didnt work.

       

      Is there configuration I may be missing?

      Do I need to place jdni.properties file somewhere else?

       

      Thanks in advance!

        • 1. Re: jndi.properties files is not read
          sfcoy

          Hi there,

           

          I don't believe that remote EJB invokation is implemented in JBoss 7.0.x. You will need the 7.1 beta for this to work.

           

          That said, jndi.properties files are not normally used in application servers (as opposed to servlet containers). This is because the container is already hosting the JNDI directory and it knows where to find stuff. If you have multiple environments then you typically federate the JNDI environment. On the other hand you would use a jndi.properties file for a standalone java client that is not executing in a container.

           

          Have a look at the sample applications in the post at http://community.jboss.org/message/639002#639003 for a working example of what you're trying to do.

           

          Cheers

          • 2. Re: jndi.properties files is not read
            snavarro89

            Hi Stephen,

             

            I try migrating to beta and the same error happened.

             

            I decided to try using the trial version of enterprise edition 5.1, and I get the same error, this is my configuration

            -----------------------------------------------------------------------------------------------------------------------

            INTERFACE

             

            package ejb;

            import javax.ejb.Local;

             

             

            @Local

            public interface HelloBeanLocal

            {

                      public String doQuery();

            }

            (I have an interface exactly the same for the remote bean)

             

            ---------------------------------------------------------------------------------------------------------------------------------------------

            CLIENT

             

            package ejb;

             

             

            import java.util.Properties;

             

             

            import javax.naming.Context;

            import javax.naming.InitialContext;

            import javax.naming.NamingException;

             

             

            public class HelloBeanClient {

             

             

                      /**

                       * @param args

                       * @throws NamingException

                       */

                      public static void main(String[] args) throws NamingException

                      {

                                Properties p = new Properties();

                                p.put(Context.INITIAL_CONTEXT_FACTORY,

                                "org.jnp.interfaces.NamingContextFactory");

                                p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

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

                                 InitialContext ctx = new InitialContext(p);

                                  HelloBean ejb = (HelloBean) ctx.lookup("Hello/bean/local");

                                  ejb.doQuery();

                      }

            }

             

            (I added the properties object because if not, I cant run the program because it says I need to specify class name in environment.)

             

            ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            This is my structure of the program

            App1

            -ejbModule

               -ejb

                 -HelloBean

                 -HelloBeanClient

                 -HelloBeanLocal

                 -HelloBeanRemote

                 -jndi.properties

               -META-INF

            -Libraries

            (NOTE: I already tried placing the jndi file in the root folder and the meta-inf, and none worked.)

            -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            This is the jndi view in the jmx console

            java:comp namespace of the component jboss.j2ee:jar=App1.jar,name=HelloBean,service=EJB3 :

             

              +- EJBContext[link -> java:internal/EJBContext] (class: javax.naming.LinkRef)
              +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
              +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
              +- env (class: org.jnp.interfaces.NamingContext)
              +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)

             

            java: Namespace

             

              +- securityManagement (class: org.jboss.security.integration.JNDIBasedSecurityManagement)
              +- comp (class: javax.namingMain.Context)
              +- XAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
              +- TransactionPropagationContextImporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
              +- policyRegistration (class: org.jboss.security.plugins.JBossPolicyRegistration)
              +- ClusteredConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- Mail (class: javax.mail.Session)
              +- TransactionPropagationContextExporter (class: com.arjuna.ats.internal.jbossatx.jta.PropagationContextManager)
              +- ProfileService (class: org.jboss.system.server.profileservice.repository.AbstractProfileService)
              +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
              +- jaas (class: javax.naming.Context)
              |   +- jmx-console (class: org.jboss.security.plugins.SecurityDomainContext)
              |   +- messaging (class: org.jboss.security.plugins.SecurityDomainContext)
              |   +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
              +- ClusteredXAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- TransactionSynchronizationRegistry (class: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)
              +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
              +- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
              +- TransactionManager (class: com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate)
              +- timedCacheFactory (class: javax.naming.Context)
            Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy cannot be cast to javax.naming.NamingEnumeration
              +- internal (class: org.jnp.interfaces.NamingContext)
              |   +- EJBContext (class: javax.ejb.EJBContext)

             

            Global JNDI Namespace

             

              +- UserTransactionSessionFactory (proxy: $Proxy99 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
              +- HelloBean (class: org.jnp.interfaces.NamingContext)
              |   +- remote-ejb.HelloBeanRemote (class: Proxy for: ejb.HelloBeanRemote)
              |   +- local (class: Proxy for: ejb.HelloBeanLocal)
              |   +- local-ejb.HelloBeanLocal (class: Proxy for: ejb.HelloBeanLocal)
              |   +- remote (class: Proxy for: ejb.HelloBeanRemote)
              +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
              +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
              +- SecureDeploymentManager (class: org.jnp.interfaces.NamingContext)
              |   +- remote[link -> DeploymentManager] (class: javax.naming.LinkRef)
              +- SecureManagementView (class: org.jnp.interfaces.NamingContext)
              |   +- remote[link -> ManagementView] (class: javax.naming.LinkRef)
              +- DeploymentManager (class: org.jboss.aop.generatedproxies.AOPProxy$4)
              +- XAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- topic (class: org.jnp.interfaces.NamingContext)
              +- ClusteredConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- ProfileService (class: org.jboss.aop.generatedproxies.AOPProxy$2)
              +- SecureProfileService (class: org.jnp.interfaces.NamingContext)
              |   +- remote[link -> ProfileService] (class: javax.naming.LinkRef)
              +- queue (class: org.jnp.interfaces.NamingContext)
              |   +- DLQ (class: org.jboss.jms.destination.JBossQueue)
              |   +- ExpiryQueue (class: org.jboss.jms.destination.JBossQueue)
              +- ClusteredXAConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
              +- ConnectionFactory (class: org.jboss.jms.client.JBossConnectionFactory)
              +- jmx (class: org.jnp.interfaces.NamingContext)
              |   +- invoker (class: org.jnp.interfaces.NamingContext)
              |   |   +- RMIAdaptor (proxy: $Proxy101 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
              |   +- rmi (class: org.jnp.interfaces.NamingContext)
              |   |   +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
              +- ProxyFactory (class: org.jnp.interfaces.NamingContext)
              |   +- App1 (class: org.jnp.interfaces.NamingContext)
              |   |   +- HelloBean (class: org.jnp.interfaces.NamingContext)
              |   |   |   +- HelloBean (class: org.jnp.interfaces.NamingContext)
              |   |   |   |   +- remote (proxy: $Proxy114 implements interface org.jboss.ejb3.proxy.impl.factory.session.SessionProxyFactory,interface org.jboss.ejb3.proxy.impl.factory.ProxyFactory,interface org.jboss.ejb3.proxy.impl.factory.session.SessionSpecProxyFactory)
              +- TomcatAuthenticators (class: java.util.Properties)
              +- console (class: org.jnp.interfaces.NamingContext)
              |   +- PluginManager (proxy: $Proxy102 implements interface org.jboss.console.manager.PluginManagerMBean)
              +- ManagementView (class: org.jboss.aop.generatedproxies.AOPProxy$3)

             

             

             

             

            Thanks

            • 3. Re: jndi.properties files is not read
              sfcoy

              JNDI issues aside, you can't do this:

               

               

              Samuel Navarro wrote:

               

                                   InitialContext ctx = new InitialContext(p);

                                    HelloBean ejb = (HelloBean) ctx.lookup("Hello/bean/local");

               

               

              from a remote client. You need to lookup the remote interface.

               
                            HelloBean ejb =(HelloBean)  ctx.lookup("HelloBean/remote");
              

               

              where the name specified above is from your own JNDI view.

              • 4. Re: jndi.properties files is not read
                jaikiran

                By the way, if you are trying something other than AS 7.x, let us know. We'll move this to be a different, more appropriate forum to avoid confusion.