I am running tomcat 8 on Windows Server 2012.
I have a web app that needs an user environment variable to be set in order to run.
I can start tomcat and retrieve the variable successfully like this:
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65
set CATALINA_HOME=C:\TOOLS\apache-tomcat-8.0.30
set CATALINA_BASE=C:\Users\ULUser\tomcat\myapp
set MY_VAR=%CATALINA_BASE%
set PATH=%CATALINA_ROOT%\bin;%PATH%
set CATALINA_OPTS="-Djava.security.properties=%CATALINA_BASE%\conf\java.security.properties"
%CATALINA_HOME%\bin\catalina.bat run
But when I run as a windows service I cannot retrieve the MY_VAR variable using System.getenv("MY_VAR");
Googling has not helped because all the pages show how to set the Java and Tomcat variables, but not how to set user variables.
I cannot set it for the entire machine because I have several instances of tomcat and each one needs a different environment variable.
I would prefer a method that involves setting the variable in the tomcat configuration rather that with windows configuration.
My alternative is to use context.xml file in tomcat and retrieve the value with logic that retrieves context settings.