enkara enkara - 1 year ago 104
Java Question

Different value of JNDI parameter for different standalone instances in GlassFish

I need to have the same application deployed in GlassFish several times, with different JNDI parameters, but I can't find a way to do that.

I know I can have different standalone instances and apply the different JNDI resources to one or several instances, but I can't have the same resource name with different values for the different instances.
What is the way to achieve what I need?

Answer Source

So in the end what I did is to use this:

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

   private String myJndiParameter;

And then since I can't use a variable to get the custom jndi parameter in an annotation, I created a @PostConstruct method, where I get the jndi value that I want, something like this:

   public void initialize ()
         myJndiParameter = (String) new javax.naming.InitialContext().lookup(appName + "/" + "my.jndi.parameter.name");
      } catch (NamingException e)
         // Treat exception

In GlassFish, my custom resource name looks like:


I'm open to suggestions to improve it :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download