users@glassfish.java.net

Re: Creating system variables and accessing them in applications

From: <glassfish_at_javadesktop.org>
Date: Thu, 15 Mar 2007 06:30:52 PST

The closest portable support for this in Java EE is the use of environment entries.
Environment entries are simple values (primitives or strings) that are assigned a
name within a private component environment and given a value in the component's
deployment descriptor.

E.g. You could define the following in a servlet
@Resource(name="targetAddr") private String targetAddress;

Then in the web.xml add the following :

 <env-entry>
         <env-entry-name>targetAddr</env-entry-name>
         <env-entry-type>java.lang.String</env-entry-type>
         <env-entry-value>http://www.something.com</env-entry-value>
</env-entry>
 
At runtime, the servlet instance targetAddress field will be injected with the configured value.
Like all environment dependencies, this value can also be looked up via
the component environment as follows :

   String address = (String) new InitialContext().lookup("java:comp/env/targetAddr");

 --ken
[Message sent by forum member 'ksak' (ksak)]

http://forums.java.net/jive/thread.jspa?messageID=208096