0

I have a glassfish application server that is running under the glassfish user on CentOS 7.2. I have an application that has a deployed application that is needing a custom environment variable (e.g. export App_Home=/opt/App).

The application is reading the environment variables in Java with within glassfish with System.getenv("App_Home").

I was able to get this to work by editing the service.

vi /etc/systemd/system/glassfish.service

Adding EnvironmentFile=/opt/MyApp/MyEnvironmentFile and then in /opt/MyApp/MyEnvironmentFile added App_Home=/opt/MyApp

  1. Is there a way of setting this environment variable with glassfish itself?

  2. Or is there a better way of setting the system property variables instead of editing service files?

I also tried adding exports into the glassfish .bashrc (which is what shell the service seems to be running under) but that didn't seem to get passed down to the application.

2

apparently there is an asenv.conf file in the glassfish directory. You could edit that (environment file).

bashrc files are used for login shells and as you have already seen for yourself, not useful for services.

8
  • I thought that was a solution as well too but that doesn't work either. I tried to add my App_Home... but when I printed out the System.getenv() from within the application it wasn't listed. Sep 1 '17 at 18:34
  • then you could modify the startserv script and add your variable there (it's a shell script, so something like export MY_AWESOME_VAR="my_awesome_value" should be enought (I just tested it and i can see the variable in /prod/pid#/environ , so I know it works) Sep 1 '17 at 20:27
  • In my glassfish.service file the ExecStart= is pointing to a jar file and start-domain which starts the glassfish service. I take it yours is pointing to just a script and not a jar file? Sep 1 '17 at 23:25
  • no, startserv is in the glassfish5/glassfish/bin/ directory of the unpacked latest-web.zip I downloaded from javaee.github.io/glassfish/download Sep 2 '17 at 6:31
  • My glassfish.service file has the following line and is what starts the service. ExecStart = /usr/bin/java -jar /home/glassfish/glassfish4/glassfish/lib/client/appserver-cli.jar start-domain I don't think the file in the startserv script is ever called which results in it never having that export ran. Sep 5 '17 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.