javalinuxserviceglassfishenvironment-variables

Where to set system variable for application running in glassfish 4


We are needing to set a system variable that our application can read that is being ran within Glassfish 4. The application is currently accessing the system variable with System.getenv().

We set an a system environment property in Windows like this:

App_Home=/opt/app/config

I have tried adding it to glassfish/glassfish4/config/asenv.conf but that didn't seem to work. I have done a bunch of searching and everything I keep running back into is setting a java property (e.g. this How to set an env variable in Glassfish 2.1). I am wanting to access the system property not a java property.

I have also tried setting the "System Properties" in the glassfish administration console under "Server (Admin Server) --> Properties --> System Properties" clicked "Add Property" and added my environment variable. However, the application still doesn't find it using System.getenv().


Solution

  • I was able to use Service Environment= option in my services file to resolve this.

    Simply adding the following worked:

    Environment="App_Home=..."
    Environment="PYTHONPATH=..."