JNDI and Bean need help

Discussion in 'Java' started by shoa, Jun 2, 2005.

  1. shoa

    shoa Guest

    Hello,

    In my Client application, to get an entity bean (EntityBean) from from
    server, I have this code in a client java file (a class):

    public static void getEBean() throws CreateException, RemoteException,
    NamingException
    {
    Properties pro = new Properties();
    pro.put("java.naming.factory.initial",
    "org.jnp.interfaces.NamingContextFactory");
    pro.put("java.naming.factory.url.pkgs",
    "org.jboss.naming:eek:rg.jnp.interfaces");
    pro.put("java.naming.provider.url","localhost:3306");
    InitialContext initialContext = new InitialContext(pro);

    //I use a SessionFacade bean

    EntityBeanSessionFacadeHome home =
    (EntityBeanSessionFacadeHome)initialContext.lookup("EntityBeanSessionFacade"
    );

    //print name for a student - for testing

    System.out.println(home.create().getStudentDetails(6).getStudentName());
    }

    This client application runs well. However, you can see that the code for
    lookup is not good as it is hard code. Therefore, I created a file called
    "jndi.properties" with the code:

    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:eek:rg.jnp.interfaces
    java.naming.provider.url=localhost:3306

    I put this file INTO the same level (e.g the same folder in hierarchy) with
    the java file above then change the code above to:

    public static void getEBean() throws CreateException, RemoteException,
    NamingException
    {
    InitialContext initialContext = new InitialContext();
    //I use a SessionFacade bean
    EntityBeanSessionFacadeHome home =
    (EntityBeanSessionFacadeHome)initialContext.lookup("EntityBeanSessionFacade"
    );
    //print name for a student - for testing

    System.out.println(home.create().getStudentDetails(6).getStudentName());
    }

    However I get a Exception

    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 untitled3.ClientEnter.getEBean(ClientEnter.java:52)
    at untitled3.ClientEnter.main(ClientEnter.java:85)


    Could you please help
    Many thanks
    S.Hoa
    shoa, Jun 2, 2005
    #1
    1. Advertising

  2. shoa

    HalcyonWild Guest

    You need to specify the properties file while creating the
    InitialContext in the second case. Also, make sure if jndi.properties
    is not a system file. I mean if a file with the same name is used by
    the app server.
    HalcyonWild, Jun 2, 2005
    #2
    1. Advertising

  3. shoa

    shoa Guest

    Hello

    Could you please tell me how to do this

    > You need to specify the properties file while creating the
    > InitialContext in the second case.


    Thanks
    shoa, Jun 3, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Takeshi
    Replies:
    0
    Views:
    502
    Takeshi
    Jan 28, 2004
  2. tmaus
    Replies:
    0
    Views:
    395
    tmaus
    Sep 13, 2004
  3. Mike S
    Replies:
    0
    Views:
    23,001
    Mike S
    Sep 16, 2004
  4. Mick
    Replies:
    2
    Views:
    9,526
    Marcin Grunwald
    Feb 23, 2005
  5. jill
    Replies:
    5
    Views:
    15,578
Loading...

Share This Page