Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3964428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:20:00+00:00 2026-05-20T03:20:00+00:00

Environment: Java (Java EE), Tomcat container At work the vast majority of our apps

  • 0

Environment: Java (Java EE), Tomcat container

At work the vast majority of our apps run in a Glassfish-container and (as typical) we have a lot of properties externalized from our apps and injected into our Glassfish-environment via the use of an app.properties file where Glassfish then exposes them to our app by making a standard system call something like this:

System.getProperty( "myProp" );

We have one particular app, however, than was deployed on a Tomcat-container (and due to the large bureaucracy here, that’s not going to change anytime soon); the original author also didn’t invest the time to research how to do a similar property-externalization using Tomcat as what is done with Glassfish. The result is that there are several things in this app where you have to comment-out some lines of code when you deploy it to our test-server and comment-out different lines of code when you deploy it to our production-server. A real pain, and potential-cause of trouble.

So I’m trying to fix that.
From my research it seems that the way to do this in Tomcat is via Tomcat’s server.xml file, something like this:

 <Environment name="myProp" type="java.lang.String" value="This is my value"/>

Then, from what I’ve read here, accessing ‘myProp’ should be the same thing as accessing an <env-entry> in the web.xml, so image I have an entry like this:

 <env-entry>
        <env-entry-name>myOtherProp</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value>This is my other value</env-entry-value>
  </env-entry>

Then I have implemented the following code in my Spring#handleRequestInternal():

Context ctx = new InitialContext();

String myProp = "<not found>";
try {
      myProp = (String) ctx.lookup( "java:comp/env/myProp" );  // from Tomcat's server.xml
} catch( Exception e ) { ... }

String myOtherProp = "<not found>";
try {
      myOtherProp = (String) ctx.lookup( "java:comp/env/myOtherProp" ); // from web.xml
} catch( Exception e ) { ... }

Yet when I log ‘myProp’ and ‘myOtherProp’, the one from my web.xml returns the correct value while the one from Tomcat’s server.xml is not found (caught by the try/catch).

What gives?
How do I set an environment-variable outside of my app via the Tomcat-container and retrieve it from within my app?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:20:00+00:00Added an answer on May 20, 2026 at 3:20 am

    Instead of putting this in server.xml it belongs in the Context.xml file for the servlet containter you’re configuring. See the tomcat Context configuration webpage. For more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java web application running on Tomcat. I want to load static
How do I set environment variables from Java? I see that I can do
We are using an Oracle 11 database and a java development environment (using Eclipse)
In my environment here I use Java to serialize the result set to XML.
At Java SE Downloads I may for example download: Java SE Runtime Environment (JRE)
I am upgrading my environment from eclipse 3.3.1 and java 1.4 to eclipse 3.4.1
How do I set Java's min and max heap size through environment variables? I
I have been tasked to develop an interactive website using java & mysql: using
We have a Java web application and we'd like to set up some basic
Lately I have been trying my hands on Eclipse IDE for java development. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.