learn groovy
learn groovy

Reputation: 527

Not able to get WebSphere environment variable in Java

I've set the environment variable under Application servers > server1 > Process definition > Environment Entries

My Property name is region and value in dev.

I'm reading this property value like below:

String environment= System.getProperty("region");

But I'm getting null, what I'm doing wrong here? I tried to set the variable under this path as well: This also returning null - how can I read the environment variable in Java?

Environment > WebSphere Variables

I'm using WebSphere version 8.0.0.3

Upvotes: 1

Views: 1662

Answers (1)

Jarid
Jarid

Reputation: 2018

Environment entries on the server's process definition are set as OS-level environment variables, not Java system properties. It's the equivalent of calling "set region=dev" on the command line before starting your JVM. Two potential approaches:

1) Use System.getenv() instead of System.getProperty() - getenv() is the method used to retrieve environment variables.

2) Instead of defining the property as an environment variable on the process, define it as a system property in the Process Definition -> Java Virtual Machine panel. You can either create a new System Property or add it to your generic JVM arguments as a -D option ("-Dregion=dev").

Upvotes: 3

Related Questions