1 Reply Latest reply on Nov 4, 2004 11:25 AM by Ricardo Coutinho

    how to set a jndi name for a mbean

    johannes rainer Newbie

      hi,
      i wrote my first mbean and everything works fine. but how can i access this mbean from, let's say, a EJB? i want to do this using:

      InitalContext ctx = new InitialContext();
      MyMBean bean = (MyMBean)ctx.lookup("myMBean");
      


      my question is now: how can i bind this mbean with the JNDI name?

        • 1. Re: how to set a jndi name for a mbean
          Ricardo Coutinho Newbie

          In the jboss docs they provide a jboss specific implementation for binding your mbean to the jndio namespace

          private void rebind() throws NamingException
          {
           InitialContext rootCtx = new InitialContext();
           Name fullName = rootCtx.getNameParser("").parse(jndiName);
           NonSerializableFactory.rebind(fullName, contextMap, true);
          }
          
          private void unbind(String jndiName)
          {
           try
           {
           InitialContext rootCtx = new InitialContext();
           rootCtx.unbind(jndiName);
           NonSerializableFactory.unbind(jndiName);
           }
           catch(NamingException e)
           {
           e.printStackTrace();
           }
          }
          


          This works well but obviously ties you to Jboss. I am just now in the process of trying to find a non-jboss specific implementation but as yet have not found one.