views:

164

answers:

1

In EJB 3.1 JNDI Lookups can be made with different Lookup-Names:

java:global[/<app-name>]/<module-name>/<bean-name>!<fully-qualifiedbean interface-name>           
java:global[/<app-name>]/<module-name>/<bean-name> 
java:app/<module-name>/<bean-name>!<fully-qualified-bean-interface-name> 
java:app/<module-name>/<bean-name> 
java:module/<bean-name>!<fully-qualified-bean-interface-name> 
java:module/<bean-name>

In my JavaEE 6 Project (with Maven 2, Netbeans 6 and Glassfish v3) the Application name is X-Snapshot.ear and the EJB-Module is Y-Snapshot.jar. How can i config this maven project to use another application and module name? I don't wnat to change all JNDI Lookups when this names change!! So is it possible to config application and module names for JNDI LookUps?

+1  A: 

Naive approach

The Maven EAR Plugin allows to Customize A Module Filename and you can set the final name or the EAR using project.build.finalName.

Much better approach

Override the <application-name> and the <module-name> in the application.xml and the ejb-jar.xml respectively. Quoting Portable Global JNDI name in EJB 3.1:

In addition to the above name, if the EJB exposes just a single client view (that is it implements just one interface or the no interface view), the container is also mandated to map the bean to

java:global/[<application-name>]/<module-name>/<bean-name>

Where

  1. <aplication-name> defaults to the bundle name (.ear file name) without the bundle extension. This can be overridden in application.xml. Also, <application-name> is applicable only if the bean is packaged inside a .ear file.
  2. <module-name> defaults to bundle name (.war or .jar) without the bundle extension. Again, this can be overridden in ejb-jar.xml.
  3. <bean-name> defaults to the unqualified class name of the bean. However, if @Stateful or @Stateless or @Singleton uses the name attribute, then the value specified there will be used as the bean name.
Pascal Thivent
Thank you Pascal.Before i read your post i tried something else which worked: In the application.xml of the ear-Module you can use <application-name>abc-app</application-name>. In the ejb-jar.xml of the ejb-Module you can use <module-name>abc-module</module-name>. Your suggestion might also work (i haven't tried it).By the way (for those reading this post): Good links concerning JNDI are:http://blogs.sun.com/MaheshKannan/entry/portable_global_jndi_nameshttp://blogs.sun.com/kensaks/entry/portable_global_jndi_nameshttp://blogs.sun.com/kensaks/entry/application_specified_portable_jndi_names
Michael W.
@Michael: Much better to override these names in the deployment descriptor. I've updated my answer.
Pascal Thivent
Okay thats perfect!
Michael W.