Define environment variables

Environment variables are constant variables that you can define in EJB modules.

For example, if you define a Circle bean, you could create an environment variable called PI and set the value to 3.1415926. If you had another enterprise bean or servlet called Cone, it could access the PI variable by doing a JNDI lookup.

To add an environment variable to an enterprise bean:

  1. In the Project Explorer view of the J2EE perspective, right-click the Deployment Descriptor for your EJB project and select Open With > Deployment Descriptor Editor to open the deployment descriptor editor.

  2. On the Bean page of the editor, scroll to the Environment Variables section and click Add. The Add Environment Variables wizard appears.

  3. Type a Name for the new variable.

  4. Select a data Type from the following choices:

    • String

    • Integer

    • Boolean

    • Double

    • Byte

    • Short

    • Long

    • Float

  5. Type a value for the new variable in the Value field. The value depends on the type of variable that you are creating.

  6. Click Finish.

The new environment variable is added and displayed in the Environment Variables section of the deployment descriptor editor.

 

Related concepts

EJB Deployment Descriptor editor