Regarding question 3 in the area of java:comp/env in the presence of EJB.
Traditionally (prior to JEE 6) java:comp/env was the module level for war modules and the EJB level for EJB in jar modules. In this model, you need to define environment entries (via resource-ref and env-entry in ejb-jar.xml , or for resource references, since JEE5 can use @Resource at the class level) for each individual EJB.
<ejb-jar> <enterprise-beans> <session> <ejb-name>B1</ejb-name> <ejb-class>p1.B1</ejb-class> <!-- ejb-class should be skipped if bean is already defined via annotation --> <env-entry> <env-entry-name>entry1</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>value1</env-entry-value </env-entry> </session> </enterprise-beans> </ejb-jar>
With JEE 6, you can deploy EJB as part of the war module. Regardless of whether the war module is deployed directly or is a part or ear module, it has one java:comp/env namespace java:comp/env shared between all servlets, EJBs, and any other code inside this module. You can define environment entries in web.xml :
<web-app> <env-entry> <env-entry-name>entry1</env-entry-name> <env-entry-type>java.lang.String</env-entry-type> <env-entry-value>value1</env-entry-value </env-entry> </web-app>
In this war based model, there can still be ejb-jar.xml for customizing other aspects of EJB, but the env-entry for the given bean in ejb-jar.xml will eventually enter the environment value for all other beans in war .
So, I would always use war archives for everything (maybe packaged in ear ).
Ivan
source share