bmk1977
bmk1977

Reputation: 141

jvm.options IBM LIBERTY

I search a lot on the web, almost all links says define JVM custom variables in jvm.options also placed it on ${server.config.dir}/jvm.options.For example I added a variable called -DAPP_ENV=PROD. But this is getting as NULL after server startup.

Any idea?

Upvotes: 2

Views: 6875

Answers (1)

Michael Thompson
Michael Thompson

Reputation: 189

It looks like you want to define an environment variable, so you have two options.

1. Use an Environment variable

In this case, you can define an environment variable (like $PATH) and load it in your app. Note this is not a JVM argument, and it will be set in the bin/server shell command used to start the server.

In the file:${server.config.dir}/server.env
Add the following line: APP_ENV=PROD
Access the value with: System.getenv("APP_ENV"); -> PROD

2. Use a System property

This is what you are trying to do, so I am not sure why it doesn't work for you, but here's how:

In the file:${server.config.dir}/jvm.options
Add the following line: -DAPP_ENV=PROD
Access the value with: System.getProperty("APP_ENV"); -> PROD

Note that in both cases these values are set at server start-up, and they are not changed dynamically (most Liberty configuration is dynamic). The JVM options and environment are sourced and set during the start script so a restart is required if you want to change either one.

My personal recommendation is go to the server.env route - its more generic and (to me) feels more appropriate since you are trying to influence the execution environment of the process, rather than defining behaviors or configuration of the JVM.

Upvotes: 6

Related Questions