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. Advertisements

  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. Advertisements

  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. Advertisements

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. Benjamin Stewart

    To bean or not to bean...

    Benjamin Stewart, Jun 30, 2003, in forum: Java
    Replies:
    0
    Views:
    978
    Benjamin Stewart
    Jun 30, 2003
  2. Markku Salminen
    Replies:
    3
    Views:
    6,074
    Michael Borgwardt
    Jan 21, 2004
  3. Takeshi
    Replies:
    0
    Views:
    759
    Takeshi
    Jan 28, 2004
  4. tmaus
    Replies:
    0
    Views:
    472
    tmaus
    Sep 13, 2004
  5. Mike S
    Replies:
    0
    Views:
    23,428
    Mike S
    Sep 16, 2004
  6. Mick
    Replies:
    2
    Views:
    10,268
    Marcin Grunwald
    Feb 23, 2005
  7. jill
    Replies:
    5
    Views:
    16,705
  8. Tom Anderson
    Replies:
    0
    Views:
    525
    Tom Anderson
    Apr 22, 2011
Loading...