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.
APP_ENV, API_URL, or DB_HOST.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
Open the environment topology
Locate the required environment in the dashboard and click Change Environment Topology.
Open the Variables section
Select the required container layer and open the Variables tab or variables configuration panel.
Add the variable
Click Add, enter the variable name and value, and repeat the action for any additional variables.
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.

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.
Connect to the container
Use Web SSH, SSH Gate, or a public-IP SSH connection to access the required node.
Open the shell profile
Edit the user profile file, commonly ~/.bash_profile or ~/.bashrc.
vi ~/.bash_profile
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"
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.
Open the configuration manager
Click Config beside the Java application-server node or layer.
Open variables.conf
Locate the stack’s variables.conf file. It is commonly included in the configuration manager’s Favorites list.
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
Restart the application server
Save the file and restart the Java node so the application server starts with the new environment values.

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.
