Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Get Module and Application Name in JEE Applications

DZone's Guide to

How to Get Module and Application Name in JEE Applications

· Java Zone
Free Resource

Make it happen: rapid app development on Kubernetes as a managed service.

For those of you who always wanted to get the name of the application or the module at runtime in a JEE application, here is a solution:

 @Resource(lookup="java:module/ModuleName")  
 private String moduleName;

 @Resource(lookup="java:app/AppName")  
 private String applicationName;  


It's been there since JEE 6 and it's easy and portable!

There is also the opportunity to get those names via JNDI lookup

String myModuleName = (String) initialContext.lookup("java:module/ModuleName");  
 String myApplicationName = (String) initialContext.lookup("java:app/AppName");  


If you don't need the names in a field but just in a single method this is the way to go.

The default module name is the base name of an ejb-jar or WAR archive.
The default application name is the base name of an EAR archive.

Tutorial: WordPress as distributed microservices on Kubernetes.

Topics:

Published at DZone with permission of Ralf Quebbemann, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}