I am not an expert on ejb-ref and why you would use it in web.xml or
ejb-jar.xml.  As I understand it the benefit is to make it easy to change
the bean information at deploy time without recompiling. We have never
needed to do that.

We do access EJBs easily from JSPs and from other EJBs, however.  The code
sample shown below is an example of how we do it.  We always use the bean's
home name, which is the classname of the implementation class by default.

This code assumes an EJB with MySampleBean as the implementation class,
MySampleHome as the home interface, and MySample as the remote interface.

        System.setSecurityManager( new RMISecurityManager() );

        /** The properties that will be used to build m_ctx. */
        Properties props = new Properties();

        /** The InitialContext which will be used when talking to the JNDI
server. */
        props.setProperty( "java.naming.factory.initial",
"allaire.ejipt.ContextFactory" );
        props.setProperty( "java.naming.provider.url",
"ejipt://127.0.0.1:2323" );

        InitialContext ctx =  new InitialContext(props);

          MySampleHome home = (MySampleHome)ctx.lookup("MySampleBean");
          MySample bean = (MySample)home.create();

The important parts are the declaration of properties as shown, and the
setting of the RMISecurityManager. This code works in JSP and in an EJB.  We
have no ejb-ref tags in our web.xml or ejb-jar.xml files. We never use
"java:comp/env/" in any of our lookups.

If this code doesn't work, check your bean's home name in the JMC to see if
it has been set to something different.

I hope this helps.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 12, 2001 11:38 AM
To: JRun-Talk
Subject: java:comp/env/ To be or not to be?


In my web.xml descriptor, I have an ejb-ref for one of my jsp/servlets.
When that jsp
does a lookup on the EJB, it finds it just fine.

In my ejb-jar.xml descriptor, I have a similar ejb-ref from EJB to EJB
(exact in all ways
except I'm making a reference to a totally different bean).

>From the "web" side of things, using the java:comp/env/ prefix to do the
lookup for
the reference in my web.xml file works just fine (appending the JNDI name
of the EJB
of course).

>From the "ejb" side of things, using that same prefix and the JNDI name of
the EJB
fails.  Why?

I'm getting an initial context in exactly the same way in both cases.  Can
someone
shed some light on this?

Robert
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/jrun-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to