GlassFish Environment Variables

Custom Environment Variables

Custom environment variables let applications receive configuration values without hardcoding them into source code. Variables can be added through the dashboard, through shell configuration files, or through the Java application-server variables file.

Environment Variables Overview

Environment variables are key-value pairs that can be read by applications and system processes. They are commonly used for database connection details, API endpoints, feature flags, runtime options, application modes, and other environment-specific settings.

Variable nameA case-sensitive identifier such as APP_ENV, API_URL, or DB_HOST.
Variable valueThe configuration value supplied to the application at runtime.
Node layer scopeDashboard variables are normally applied to all containers in the selected environment layer.
Restart requirementSome stacks require a node restart before new or modified variables become available to running processes.
i

Default and custom variables

The platform supplies a set of default variables automatically. Avoid replacing a predefined value unless the relevant stack documentation explicitly allows it.

Add Variables through the Dashboard

1

Open the environment topology

Locate the required environment in the dashboard and click Change Environment Topology.

2

Open the Variables section

Select the required container layer and open the Variables tab or variables configuration panel.

3

Add the variable

Click Add, enter the variable name and value, and repeat the action for any additional variables.

4

Apply the topology change

Click Apply to save the variables for the selected layer. Restart the affected nodes when the stack does not reload variables automatically.

Add custom environment variables through the dashboard
Add variable names and values for the selected container layer.

Recommended method

Use the dashboard Variables panel whenever the selected stack supports it. The values remain associated with the environment topology and are applied consistently to all nodes in the layer.

Set Variables through SSH

Variables can also be defined in shell configuration files through SSH. This method is useful for command-line tools or stacks where variables are not managed through the dashboard.

1

Connect to the container

Use Web SSH, SSH Gate, or a public-IP SSH connection to access the required node.

2

Open the shell profile

Edit the user profile file, commonly ~/.bash_profile or ~/.bashrc.

vi ~/.bash_profile
3

Export the required values

Add one export statement for each variable.

export APP_ENV="production"
export API_URL="https://api.example.com"
export FEATURE_FLAG="enabled"
4

Load the updated profile

Start a new SSH session or load the file into the current shell.

source ~/.bash_profile
!

Process visibility

Variables added to an interactive shell profile are not always inherited by services started through systemd, an application server, a process manager, or another non-interactive runtime. Use the stack-specific configuration method when the application service cannot read shell-profile variables.

Set Variables for Java Application Servers

Java application-server containers provide a dedicated variables.conf file for custom environment variables and JVM-related values.

1

Open the configuration manager

Click Config beside the Java application-server node or layer.

2

Open variables.conf

Locate the stack’s variables.conf file. It is commonly included in the configuration manager’s Favorites list.

3

Add custom variables

Enter the required key-value pairs using the format supported by the Java stack.

APP_ENV=production
API_URL=https://api.example.com
FEATURE_FLAG=enabled
4

Restart the application server

Save the file and restart the Java node so the application server starts with the new environment values.

Custom environment variables in variables.conf
Add Java application-server variables in the variables.conf file.

Verify Variable Values

Use the command line to confirm that a variable is available in the current shell:

echo "$APP_ENV"
printenv API_URL
env | grep FEATURE_FLAG

For application processes, use the application’s diagnostic page, framework console, logs, or runtime command to verify that the service has received the new value.

Test before production use

Confirm the variable inside the actual application process. A value visible in an SSH shell may still be unavailable to a service that was started before the variable was added.

Security Recommendations

  • Do not place credentials directly in source-code repositories.
  • Limit access to environment settings and configuration files.
  • Avoid printing secret values in application logs or diagnostic pages.
  • Use separate credentials for development, testing, and production environments.
  • Rotate passwords, tokens, and private keys according to the organization’s security policy.
  • Review copied variables after cloning an environment.
  • Remove variables that are no longer used.
!

Secret-management limitation

Environment variables reduce hardcoded configuration but are not a complete secret-management system. Highly sensitive values may require a dedicated vault or external secrets service.

Expected Result

The required custom variables are available to the selected container layer or application process, allowing environment-specific configuration to be changed without modifying the application source code.

Important Notes

  • Variable names are case-sensitive.
  • Do not overwrite platform default variables unless the stack documentation permits it.
  • Dashboard variables are generally applied to the selected node layer.
  • Shell-profile variables may not be inherited by background services.
  • Restart the affected node or service when required.
  • Review variable values after environment cloning, migration, or topology changes.

Common Issues and Solutions

Variable is emptyCheck the exact variable name, capitalization, quoting, and whether the correct node or layer was configured.
Shell can read it but the application cannotRestart the service and use the stack-specific dashboard or configuration-file method instead of an interactive shell profile.
Value contains spaces or special charactersQuote or escape the value according to the selected shell or configuration-file syntax.
Variable disappears after redeploymentStore it through the dashboard Variables panel or in a configuration path preserved by the stack.
Wrong credentials used after cloningReview and replace environment-specific secret values in the cloned environment before enabling production traffic.