0

Is there a way to find out the deployment name of an application from a server managed object that itself is in, on Weblogic 11g? For example, can I get the application name a stateless bean in deployed with, from that stateless bean itself?

I found some servers allow for JNDI lookup of java:app/AppName, but it doesn't seem to work on Weblogic. Also, I know I can get the names of all the deployed applications (and much more) using MBean, but I don't know how to identify 'the one' that I'm interested in without previously passing the application name to my bean, which defeats the purpose.

devwebcl
  • 2,866
  • 3
  • 27
  • 46
milin
  • 414
  • 4
  • 14

1 Answers1

1

Quoting the Java EE 8 specification, ch. EE.5.15 "Application Name and Module Name References"

A component may access the name of the current application using the pre-defined JNDI name java:app/AppName. A component may access the name of the current module using the pre-defined JNDI name java:module/ModuleName. Both of these names are represented by String objects.

And later, at EE.5.15.2 "Java EE Product Provider’s Responsibilities":

The Java EE Product Provider is responsible for providing the correct application name and module name String objects as required by this specification.

So Java EE compliant products are required to provide the JNDI value you mention.

For me (currently on WildFly 15) this works:

@Resource(name = "java:app/AppName")
private String appName;

@Resource(name = "java:module/ModuleName")
private String moduleName;
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Nikos Paraskevopoulos
  • 39,514
  • 12
  • 85
  • 90
  • We are running WebLogic Server 10.3.4.0 with Java 1.6.0_37. I'm not sure whether this is the cause (most likely is), but your examples, when put in a stateless EJB bean, yield null values. Other resources get injected as expected. – milin Jul 08 '20 at 14:42
  • Yes, you are probably running on a server that supports an older version of J(2)EE that does not specify these JNDI values (I do no think the Java version plays a role). Can you tweak the deployment descriptors of your modules? I believe you can still add JNDI entries of type `String` from the deployment descriptors - but under the `java:comp/env` namespace. – Nikos Paraskevopoulos Jul 08 '20 at 16:21
  • Currently, I use this approach, in a somewhat different arrangement. I use an ant script to deploy to WL and pass in the application name as a normal string resource using the deployment plan. This is, however, cumbersome, and I would like to avoid it if possible. The whole motivation of trying to get the application name dynamically is to avoid doing it "manually". – milin Jul 08 '20 at 17:07