This content has been marked as final.
Show 7 replies
-
1. Re: Programmatically determining ear name for JNDI lookups:
waynebaylor Sep 13, 2007 10:47 AM (in response to jnorris10)you should override the default JNDI names by using the jboss annotations @LocalBinding, @RemoteBinding OR by using the jboss.xml deployment descriptor.
-
2. Re: Programmatically determining ear name for JNDI lookups:
jnorris10 Sep 13, 2007 1:26 PM (in response to jnorris10)"waynebaylor" wrote:
you should override the default JNDI names by using the jboss annotations @LocalBinding, @RemoteBinding OR by using the jboss.xml deployment descriptor.
As I tried to communicate above, I *want* to put these components into JNDI under an ear-like context. I don't want to hard-code another ear-like name into @LocalBinding since this module needs to be a part of multiple ears and therefore have multiple JNDI bindings. I don't want to hard-code it into jboss.xml either since then I have a lot of near-useless configuration details to manage when I put this component into multiple ears.
Currently I put the ear name in a custom configuration file in the EAR, and looking it up when I need to lookup components. However, it would be handy to be able to ask some service what my current ear context name was. -
3. Re: Programmatically determining ear name for JNDI lookups:
waynebaylor Sep 14, 2007 10:00 AM (in response to jnorris10)i would recommend that you not include the EAR name at all in your JNDI names. for example, if you have the bean class:
@Stateless @Local(com.mycomp.MyLocal.class) @Remote(com.mycomp.MyRemote.class) public class MyBean implements MyLocal, MyRemote { ... }
then you should bind its interfaces to meaningful JNDI names (the EAR name can be changed by anyone so it's not meaningful):@Stateless @Local(com.mycomp.MyLocal.class) @Remote(com.mycomp.MyRemote.class) @LocalBinding(jndiBinding="com.mycomp.MyLocal") @RemoteBinding(jndiBinding="com.mycomp.MyRemote") public class MyBean implements MyLocal, MyRemote { ... }
As for the multiple EARs part:1) If you're including it in multiple EARs which will be deployed on the same App. Server, then you will need to include some Class Loading Isolation. You can continue to customize the JNDI name with your config file (i just wouldn't use the EAR name as part of it).
2) If the EARs won't be deployed on the same App. Server, then you won't need the config file anymore. -
4. Re: Programmatically determining ear name for JNDI lookups:
jnorris10 Sep 15, 2007 3:08 AM (in response to jnorris10)Thanks for your reply. I'm starting to thing that a config file in the ear with a ear-like context name to use for the JNDI root is not such a bad solution.
-
5. Re: Programmatically determining ear name for JNDI lookups:
wolfc Sep 17, 2007 5:09 AM (in response to jnorris10)Have you tried using ejb-links?
<ejb-local-ref> <ejb-ref-name>ejb/myBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>com.mycomp.MyLocal</local> <ejb-link>MyBean</ejb-link> </ejb-local-ref>
MyLocal bean = (MyLocal) new InitialContext().lookup("java:comp/env/ejb/myBean");
-
6. Re: Programmatically determining ear name for JNDI lookups:
jnorris10 Sep 17, 2007 1:17 PM (in response to jnorris10)"wolfc" wrote:
Have you tried using ejb-links?<ejb-local-ref> <ejb-ref-name>ejb/myBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>com.mycomp.MyLocal</local> <ejb-link>MyBean</ejb-link> </ejb-local-ref>
MyLocal bean = (MyLocal) new InitialContext().lookup("java:comp/env/ejb/myBean");
I don't think I have an ENC in an unmanaged component, do I? Isn't that a managed component concept? I only need to lookup stuff from JNDI for unmanaged components. -
7. Re: Programmatically determining ear name for JNDI lookups:
wolfc Sep 17, 2007 2:05 PM (in response to jnorris10)Ah I thought you were talking about doing lookups from components within the EAR. Note that unmanaged components which are used by a managed component can access java:comp/env from that managed component.