How to create an environment entry in the EJB deployment descriptor and look it up at runtime.
See the part on developing Enterprise JavaBeans in the Programmer's Guide |
Any value that you might want to set that is not a resource reference, a bean reference or a security role, can be set as an environment property. For example, the SilverStream BankDemo uses a String variable called bank_name which allows the deployer to change the name displayed at runtime.
To use the JAR Designer to add an environment variable to the deployment descriptor, you add the environment entry and specify its properties as shown here:
The information that you set in the deployment descriptor includes the following:
At deployment time, the Container adds this entry (and any other environment entries) to the naming context's environment namespace.
You can find an environment property using the following code to look it up:
InitialContext m_initialContext = new InitialContext(); m_sBankName = (String) m_initialContext.lookup("java:comp/env/bank_name");
or if you need to look up more than one:
InitialContext m_initialContext = new InitialContext(); Context contextEnv = (Context) m_initialContext.lookup("java:comp/env"); String m_sBankName = (String) contextEnv.lookup("bank_name"); // Return the bank name. return m_sBankName;