When running an Java EE application, in different situations it’s useful to know it’s own module and application name. In order to get these it is possible to access them via JNDI.
Why to access these names?
Each Java container provides a number of different JNDI-Resources that can be accessed within an application (.ear). So the application name is provided as well as the module name. In case the name of the application was changed during deployment or the name of a module was changed in the
application.xml, being able to get the name at runtime is really blessing. Accessing the application name is possible by using
java:app/AppName, whereas accessing module name is possible by using
Furthermore for logging or debugging purpose having access to these might be exactly what you need. Accessing these names at runtime results in no questions whether there was an invalid configuration of the application or not.
Accessing the names
The following code example demonstrates accessing the names with Dependency Injection.
private String moduleName;
private String appName;
In case there is no Dependency Injection it is possible to access the values by directly using
- How to get module name and app name
- Java EE 6/7/8 Specification