Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Ubuntu's default installation of Tomcat 6. I'm deploying a ROOT.war, and trying to set an environment variable specific to it, i.e. accessible from System.getenv() in the Servlet.init(config).

According to the docs (, I can specify this in a Context element in conf/Catalina/localhost/ROOT.xml. I've created that with these contents:

  <Environment name="FOO" value="bar" type="java.lang.String" override="false"/>

And I've deployed the webapp as usual, i.e. to webapps/ROOT.war.

Server.getenv("FOO") in the Servlet.init(config) still returns null. What am I missing?

share|improve this question
up vote 2 down vote accepted

From the Tomcat users mailing list:

It's not entirely clear from the Tomcat documentation, but you aren't creating environment variables that can be retrieved using System.getenv. Instead, you are placing entries into the JNDI context.

You'll want to retrieve them like this:

// Obtain our environment naming context Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env");

String FOO = (String)envCtx.lookup("FOO");

// now FOO should have the value "bar" from your

The documentation for JNDI resources can be found here:

Hope that helps, - -chris

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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