Hi Pedro,

The spec doesn't describe or address extra-ear component
interaction(yet), altough it does require support for RMI-IIOP as the
standard transport for enterprise class RPC, so this depends entirely on
the app server you use. I'm afraid I'm unfamiliar with the RI, but at
deploy time many servers will allow you to link to components in
different machines/ears.

The easiest(but not necessarily the one that suits you best) way around
this is to include the EJB jar in the EAR you're deploying.

Should you come from the M$ world, perhaps you're familiar with
COM/MTS/COM+. If you use VB, you'll use:

CreateObject(ProgId, ServerName)

Where ProgId is the "friendly name" of a component, e.g.:
"ADOR.Recordset", "CDO.Contact", etc. A map that allows to identify
components based on the friendly name is in the Wi
And ServerName(optional) is the resolvable name of a server, e.g.:
"MAINSERVER","201.10.20.30", etc.

In J2EE, we have JNDI to replace the Registry, and rely on the OS host
resolving hosts. Even if your app server doesn't include support for
linking references to beans in different machines/ears, you should still
be able to get references to EJBs (remote/home interfaces) by manually
connecting to the JNDI implementation on a particular server(here's an
example that works in Orion/OC4J):

/**
   * Gets the context.
   * @param environment Should be the prefix in the properties file
(i.e.
development,test,production)
   * @returns The jndiContext to the App Server.
   */
  protected Context getContext(String environment)
  {
    if(jndiContext == null)
    {
        jndiContext.close();
    }
      try
      {
        String applicationServer =
"com.evermind.server.ApplicationClientInitialContextFactory";
        String applicationServerUrl = "ormi://fred"); //will use Orion's
RMI at machine fred
        String appServerLogin = "user";
        String appServerPassword = "1234";

        Hashtable props = new Hashtable();
        props.put("java.naming.factory.initial", applicationServer);
        props.put("java.naming.provider.url", applicationServerUrl);
        props.put("java.naming.security.principal", appServerLogin);
        props.put("java.naming.security.credentials",
appServerPassword);

        jndiContext = new InitialContext(props);
      }
      catch(Exception e)
      {}
    }
    return jndiContext;
  }

Basically, this code will return a JNDI Context to the machine "fred",
provided that the credentials provided are valid.

The other thing you need to remember is that while you're not required
to physically import a component you want to use, the client
application(a web app in this case) needs to have access to the
interfaces your component implements, just like in COM(TLB, type
libraries). Therefore your web app, if not in the same ear, will need to
have the Remote and Home interfaces in their classpath.

Finally, if you deploy your EJBs in a different EAR than your web app,
chances are that all communication between the two cannot benefit from
Local interfaces, thereby resulting in a more slow application. Local
interfaces leverage the fact that client and server are colocated, and
running in the same JVM, to implement speed gains on the communication.
It's also much like COM, that in method invocation values and objects
passed must be marshalled. Local interfaces allow the marshalling to be
simpler, therefore resulting in more efficient code.


HTH,


Juan Pablo Lorandi
Chief Software Architect
Code Foundry Ltd.
[EMAIL PROTECTED]

Barberstown, Straffan, Co. Kildare, Ireland.
Tel: +353-1-6012050  Fax: +353-1-6012051
Mobile: +353-86-2157900
www.codefoundry.com


> -----Original Message-----
> From: A mailing list for Enterprise JavaBeans development
> [mailto:EJB-INTEREST@;JAVA.SUN.COM] On Behalf Of psalazar
> Sent: Monday, October 28, 2002 6:47 PM
> To: [EMAIL PROTECTED]
> Subject: acessing ejb in jsp
>
>
> Greetings,
>
> I created a EJB and I deployed it in my J2EE (j2ee1.3.1)
> inside in EAR. Then I created a web application and i put it
> inside of another EAR. But then when I verify it on
> deploytool, it throws a FAIL message saying it cannot find
> the ejb classes that I use in my JSP (web application).
>
> So my question is, for I use a EJB from another EAR, must I
> in my web application put all classes files (jar maybe?) from
> that EJB? If true it doesn't makes much sense. I should be
> able to refer another EJB without import *physically* my
> other EJB to my EAR, shouldn't I?
>
> thanks,
> Pedro Salazar
> --
> pedro salazar (pt-inovacao) <[EMAIL PROTECTED]>
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body of the message "signoff EJB-INTEREST".
> For general help, send email to [EMAIL PROTECTED] and
> include in the body of the message "help".
>
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to