I am running tomcat 8 on windows 2012.

I have a webapp 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 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.

  • stackoverflow is better for this.
    – Ungeheuer
    Nov 7, 2016 at 1:38

1 Answer 1


Services can have an environment set up specifically for them. I've already demonstrated how to do this for the Windows Update service. Just apply the same logic for the Tomcat service application.

This is a very Super User way of doing it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .