Java EE 6: How to get module name and app name

Posted by user12798506 on Oracle Blogs See other posts from Oracle Blogs or by user12798506
Published on Tue, 30 Oct 2012 06:48:15 +0000 Indexed on 2012/10/30 11:12 UTC
Read the original article Hit count: 327

Filed under:

Java EE 6??????????????????????????????????????????????? ???????????????[1] ?????????????JNDI???????????????????"java:module/ModuleName"?????? ?????"java:app/AppName"????????

InitialContext ctx = new InitialContext();
String moduleName = ctx.lookup("java:module/ModuleName");  // ??????
String appName = ctx.lookup("java:app/AppName");           // ?????????

???@Resource??????????????????????????????????????????

@Resource(lookup="java:module/ModuleName")
String moduleName;                          // ??????????????????
@Resource(lookup="java:app/AppName")
String appName;                             // ?????????????????????

???EAR???????Web????????EJB??????????????????AppName???????????????? ?????????GlassFish V3 (3.1.2.2)?WebLogic 12c (12.1.1)?JBoss AS 7 (7.1.1)?????????? ????????????????AppName???ModuleName???????????????

?????????Web Profile??????????????????(GlassFish?JBoss?????Web Profile ?????)?????Apache TomEE (1.5.0)????????ModuleName???"localhost/<Web?????? >"??????????????????????????????????????

Java EE 6??????????????????????????????????????????????? ??????????????????????????????????????????????????? ???????????????????????????????????????????????????? ????????

???Apache Tomcat 7.0?Servlet 3.0??????????????????????????????·??? ???????JNDI????????????????????????

??:?Tomcat????????Java EE??????????????????????


[1] Java EE 6????(JSR 316)????????????? (pp.122-123):

EE.5.15 Application Name and Module Name References

A component may access the name of the current application using the pre-defined JNDI name java:app/AppName. A component may access the name of the current module using the pre-defined JNDI name java:module/ModuleName. Both of these names are represented by String objects.

© Oracle Blogs or respective owner

Related posts about /Design