Skip to Content
avatar image
Former Member

Connecting to EJB


I have basic EJB question.

I have programmed JSP application with EJB that is using BAPI's and it is running on SAP J2EE server.

But now I would like to create simple console Java application that uses EJB from J2EE server and will located on remote computer with Java SDK.

I have no idea how to use remote EJB on simple Java application. I was looking on Google but only found source for connecting EJB with JSP application (what is in my case useless).

Does any body have any example source how can I do this?

Thank you in advance.



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 11, 2005 at 03:23 PM

    Hello Mihail,

    this code is working fine remotely for me:

    import javax.naming.InitialContext;
    import java.util.Properties;
    Properties _param = new Properties();
    _param.put(Context.INITIAL_CONTEXT_FACTORY,	"");
    _param.put(Context.PROVIDER_URL, "BFDB8D29491:50004");
    _param.put(Context.SECURITY_PRINCIPAL, "Administrator");
    _param.put(Context.SECURITY_CREDENTIALS, "password");
    Context initialContext = new InitialContext(_param);
    Object obj = initialContext.lookup("");
    HelloHome hh = (HelloHome)obj;
    Hello h = hh.create(); 

    Best regards, Maksim Rashchynski.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Ivaylo and Maksim!

      Thank you very much for your help.

      My Problem is now solved!

      Best regards Mihail

  • avatar image
    Former Member
    Nov 11, 2005 at 03:07 PM

    Hi Mihail,

    accessing an EJB from a standalon remote Java application differs mainly in the lookup string that you use to lookup the bean's interface (i.e. you can't look it up relative to the java:comp/env context). Also, to access the bean from remote virtual machine, you must ensure the beans uses remote interfaces (as opposed to the local ones when you access it from the same VM).

    A general description of the ways you can access a bean are described in">this> article on SDN. You're particularly interested in the Example 3: Accessing Enterprise Beans by Non-J2EE Components section.

    Also, keep in mind that you'll need the client classes of the bean's interfaces (the client.jar) on the client side. This">This> page in the docs explains how you get that.

    Hope that helps!

    Add comment
    10|10000 characters needed characters exceeded