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 7911385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:13:42+00:00 2026-06-03T13:13:42+00:00

I know that there is a configuration file called web.xml What I want to

  • 0

I know that there is a configuration file called web.xml
What I want to achieve is have another configuration file that has application specific configuration and it has to be read when the web server is started. I also want a Class to be able to read this configuration. Is there a way I can configure this is web.xml file itself or is there another way

  • 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-06-03T13:13:45+00:00Added an answer on June 3, 2026 at 1:13 pm

    You can use the Apache Commons Configuration. Have a look at the user guide. Since you want it to be done on startup here is a sample ServletContextListener:

    package test;
    
    import java.io.File;
    import java.net.MalformedURLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    import org.apache.commons.configuration.Configuration;
    import org.apache.commons.configuration.ConfigurationException;
    import org.apache.commons.configuration.XMLConfiguration;
    
    public class ConfigurationListener implements ServletContextListener {
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            ServletContext context = sce.getServletContext();
            File configFile;
    
            try {
                configFile = new File(context.getResource("/WEB-INF/configuration.xml").getPath());
                Configuration config = new XMLConfiguration(configFile);
                context.setAttribute("configuration", config);
            } catch (ConfigurationException | MalformedURLException ex) {
                Logger.getLogger(ConfigurationListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {}
    }
    

    Now get your configuration anywhere in your web application like this:

    Configuration config = (Configuration) request.getServletContext().getAttribute("configuration");
    

    I would create a class to hold the configuration though rather than adding it as an attribute to the ServletContext. The class would simply provide access to the configuration through a static method.

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

Sidebar

Related Questions

Here is my situation: I have an application that use a configuration file. The
I know that there're stdout/in/err for a program and I want to redirect a
I have a bunch of Yaml configuration files that I want to convert to
I know that JMS Queues can be created in HornetQ via the hornetq-jmx.xml Configuration
I have situation, where I want to read configuration file only one time, when
I have an application that sends the customer to another site to handle the
I understand that there's an nginx configuration file at http://www.friendfeed.com But i don't really
I know that there are lots of examples out there on this, but they
I know that there can be multiple values for an email, but I'm not
I know that there are many Delphi database related questions available, but I'm considering

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.