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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:26:59+00:00 2026-05-13T13:26:59+00:00

In my web application I have to send email to set of predefined users

  • 0

In my web application I have to send email to set of predefined users like finance@xyz.example, so I wish to add that to a .properties file and access it when required. Is this a correct procedure, if so then where should I place this file? I am using Netbeans IDE which is having two separate folders for source and JSP files.

  • 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-13T13:26:59+00:00Added an answer on May 13, 2026 at 1:26 pm

    It’s your choice. There are basically three ways in a Java web application archive (WAR):


    1. Put it in classpath

    So that you can load it by ClassLoader#getResourceAsStream() with a classpath-relative path:

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream input = classLoader.getResourceAsStream("foo.properties");
    // ...
    Properties properties = new Properties();
    properties.load(input);
    

    Here foo.properties is supposed to be placed in one of the roots which are covered by the default classpath of a webapp, e.g. webapp’s /WEB-INF/lib and /WEB-INF/classes, server’s /lib, or JDK/JRE’s /lib. If the propertiesfile is webapp-specific, best is to place it in /WEB-INF/classes. If you’re developing a standard WAR project in an IDE, drop it in src folder (the project’s source folder). If you’re using a Maven project, drop it in /main/resources folder.

    You can alternatively also put it somewhere outside the default classpath and add its path to the classpath of the appserver. In for example Tomcat you can configure it as shared.loader property of Tomcat/conf/catalina.properties.

    If you have placed the foo.properties it in a Java package structure like com.example, then you need to load it as below

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    InputStream input = classLoader.getResourceAsStream("com/example/foo.properties");
    // ...
    

    Note that this path of a context class loader should not start with a /. Only when you’re using a "relative" class loader such as SomeClass.class.getClassLoader(), then you indeed need to start it with a /.

    ClassLoader classLoader = getClass().getClassLoader();
    InputStream input = classLoader.getResourceAsStream("/com/example/foo.properties");
    // ...
    

    However, the visibility of the properties file depends then on the class loader in question. It’s only visible to the same class loader as the one which loaded the class. So, if the class is loaded by e.g. server common classloader instead of webapp classloader, and the properties file is inside webapp itself, then it’s invisible. The context class loader is your safest bet so you can place the properties file "everywhere" in the classpath and/or you intend to be able to override a server-provided one from the webapp on.


    2. Put it in webcontent

    So that you can load it by ServletContext#getResourceAsStream() with a webcontent-relative path:

    InputStream input = getServletContext().getResourceAsStream("/WEB-INF/foo.properties");
    // ...
    

    Note that I have demonstrated to place the file in /WEB-INF folder, otherwise it would have been public accessible by any webbrowser. Also note that the ServletContext is in any HttpServlet class just accessible by the inherited GenericServlet#getServletContext() and in Filter by FilterConfig#getServletContext(). In case you’re not in a servlet class, it’s usually just injectable via @Inject.


    3. Put it in local disk file system

    So that you can load it the usual java.io way with an absolute local disk file system path:

    InputStream input = new FileInputStream("/absolute/path/to/foo.properties");
    // ...
    

    Note the importance of using an absolute path. Relative local disk file system paths are an absolute no-go in a Java EE web application. See also the first "See also" link below.


    Which to choose?

    Just weigh the advantages/disadvantages in your own opinion of maintainability.

    If the properties files are "static" and never needs to change during runtime, then you could keep them in the WAR.

    If you prefer being able to edit properties files from outside the web application without the need to rebuild and redeploy the WAR every time, then put it in the classpath outside the project (if necessary add the directory to the classpath).

    If you prefer being able to edit properties files programmatically from inside the web application using Properties#store() method, put it outside the web application. As the Properties#store() requires a Writer, you can’t go around using a disk file system path. That path can in turn be passed to the web application as a VM argument or system property. As a precaution, never use getRealPath(). All changes in deploy folder will get lost on a redeploy for the simple reason that the changes are not reflected back in original WAR file.

    See also:

    • getResourceAsStream() vs FileInputStream
    • Adding a directory to tomcat classpath
    • Accessing properties file in a JSF application programmatically
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have C# web application that I want it to send out an email
I have a web application that registered users use. These users have good email
I have a Django-based web application that is required to send a confirmation email
I have a web application where I wish to send information to a database.
In my web application we have many users.I want to set permission for each
I have web application (asp.net) located on web server. I need to send email
In my web application I have taken a ajax calendar in that i want
In my web application users have the ability to upload games which are then
I am building a web application and have been told that using object oriented
I need to send email notifications in my Java web application. I'm using Apache

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.