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

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

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 }}