Environment properties

When you deploy a J2EE application, use the deployment descriptor to define all the environment properties that the application component needs to access. This sample code defines the environment property (env-entry) maxExemptions as an Integer and sets its value to 10:

<env-entry>
   <description>
     The maximum number of tax exemptions
   </description>
   <env-entry-name>maxExemptions</env-entry-name>
   <env-entry-type>java.lang.Integer</env-entry-type>
   <env-entry-value>10</env-entry-value>
</env-entry>

The information between the opening and closing env-entry tags defines an environment entry element, which consists of:

Within the same container, all instances of an application component share the same environment properties. The component instances cannot modify the environment at runtime.

An application component instance uses the JNDI interfaces to locate the environment naming context and access the environment properties. To locate the naming context, an application creates a javax.naming.InitialContext object and gets the InitialContext for java:comp/env. In this example, the application retrieves the value of the environment property maxExemptions and uses that value to determine an outcome:

Context initContext = new InitialContext();
Context myEnv = 
   (Context)initContext.lookup(“java:comp/env”);

// Get the maximum number of tax exemptions
Integer max=(Integer)myEnv.lookup(“maxExemptions”);

// Get the minimum number of tax exemptions 
Integer min = (Integer)myEnv.lookup(“minExemptions”);

// Use these properties to customize the business logic
if (numberOfExemptions > max.intValue() ||
   (numberOfExemptions < min.intValue())
    throw new InvalidNumberOfExemptionsException();

NoteDefault name service When you call the empty constructor to create a new InitialContext, EJB Server sets the Context.INITIAL_CONTEXT_FACTORY system property and sets the EJB Server EJB name service as the default.