# Environment variable for TOMCAT based application



## Peter2121 (May 4, 2019)

I need to pass an environment variable to my application, working under tomcat8. It's a custom variable, nothing to do with tomcat himself.
I tried to put it into /etc/login.conf, I tried to put it into /etc/rc.local, but it is still not visible by my app. The startup script of tomcat is the default one. I can see the variable under root.
Any advise?


----------



## tingo (May 7, 2019)

Clue: which user does tomcat run as?


----------



## Peter2121 (May 8, 2019)

It runs (by default) under 'www' user


----------



## tingo (May 8, 2019)

And does the user 'www' see this variable?


----------



## Peter2121 (May 9, 2019)

Evidently non.
It's impossible to login under this user to the console, so I can just do `sudo -u www env`, and the variable is not here.
My app under Tomcat does not see it neither.


----------



## usdmatt (May 9, 2019)

You could try the following:

/etc/rc.conf

```
tomcat8_prepend="env VAR=VALUE"
```

According to rc(), this should be prepended to the command that runs tomcat. env() will set the specified variables then run the command.


----------



## zirias@ (May 9, 2019)

In general, you can always create a file /etc/rc.conf.d/<servicename> that's automatically sourced, so you can define and export environment variables there for a specific service.


----------

