Without testing, does
give anything reasonable? (perhaps some other stuff in JNDI?)
No luck with JNDI it did lead me to using the initial context to look up the app name.
String aname = (String) initialContext.lookup("java:app/AppName"); //EAR, returns ABCD
String mname = (String) initialContext.lookup("java:module/ModuleName"); //WAR, returns XYZ
It's not ideal, but it works for the moment.
Edit: Had my lookups backward the first time
Yep, forgot to say that resource injection only works for managed beans but it's essentially the same thing you did manually.