Programmatically determining JNDI root context / ear name in JBoss 5.1
Asked Answered
D

2

6

The default jndi context in JBoss 5.1 for an EJB is "earname/ejbname/local". In some instances where injection is not available I need to manually do a jndi lookup, however if my ejb jar file is packaged in different EAR's I'd like to have a portable way to maintain a look up helper class.

I know a method to do this exists as I've seen it before but can't find it now. I'd like to programmatically find the current application name or ear name.

Any ideas?

Decahedron answered 4/11, 2010 at 20:39 Comment(0)
M
8

Found through trial & error for jboss 6.1:

    InitialContext ic = new InitialContext();
    String moduleName = (String) ic.lookup("java:module/ModuleName");
    String appName = (String) ic.lookup("java:app/AppName");
Mizzen answered 29/10, 2013 at 0:6 Comment(0)
T
1

I know a method to do this exists as I've seen it before but can't find it now. I'd like to programmatically find the current application name or ear name.

I'm not aware of any obvious way to do that (not saying it's impossible, although I think the application name or ear name are more a "deployer" role concern) and my suggestion would be to either:

  • override the default JNDI names using a jboss.xml ~or~
  • read a properties file (and have your build system generate it) from your service locator

See also

Terricolous answered 8/11, 2010 at 15:7 Comment(1)
Thanks, I'm aware of those alternatives, but that doesn't really address my question.Decahedron

© 2022 - 2024 — McMap. All rights reserved.