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

The Archive Base Latest Questions

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

I am trying to access the i18n properties file I’m using in my JSF

  • 0

I am trying to access the i18n properties file I’m using in my JSF application in code. (The idea is to have a page that displays its keys and values as a table actually.)

The project is a maven project, and in the src/resources/localization folder, and deployed in the war file in WEB-INF\classes\localization\

java.util.Properties prop = new java.util.Properties();
String path = "localization/stat_codes.properties";
InputStream foo = prop.getClass().getResourceAsStream(path);

But the variable foo turns out to be null whatever I set the path variable to, /WEB-INF/classes/localization/stat_codes.properties, “localization.stat_codes.properties” etc. A similar question is here, but there is no helpful answer there as well.

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

    The Class#getResourceAsStream() can take a path which is relative to the location of the Class which you’re using there as starting point. So, for example, if the class is located in the com.example package and you request the path foo/filename.properties, then it will actually load the com/example/foo/filename.properties file. But if you use /foo/filename.properties, then it will actually load foo/filename.properties from the classpath root.

    So, your code

    java.util.Properties prop = new java.util.Properties();
    String path = "localization/stat_codes.properties";
    InputStream foo = prop.getClass().getResourceAsStream(path);
    

    will actually look for java/util/localization/stat_codes.properties file.

    But in applications with a complex multiple classloader hierarchy, the one classloader isn’t the other. The classloader which loaded the core Java classes does not necessarily have knowledge about files which are in the webapp’s /WEB-INF/classes. So prefixing the path with / will not necessarily be the solution, it would still return null.

    If you can guarantee that the current class is visible by the same classloader as the properties files (because they’re in the same sub-root of the classpath, e.g. /WEB-INF/classes, then you should indeed use

    String path = "/localization/stat_codes.properties";
    InputStream foo = this.getClass().getResourceAsStream(path);
    

    But if at some point, the properties files will be externalized because of more easy maintenance/editing during runtime so that you don’t need to rebuild/redeploy/restart the webapp whenever you want to edit the files, then the above line of code will likely fail as well. The externalized location would be only accessible by a different classloader. The canonical solution is to use the thread’s context classloader as starting point instead, it has access to all resources in the classpath.

    String path = "localization/stat_codes.properties";
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    InputStream foo = loader.getResourceAsStream(path);
    

    (note that this one cannot take a path starting with /, it’s always relative to the common root)

    See also:

    • Where to place and how to read configuration resource files in servlet based application?
    • ExternalContext#getResourceAsStream() returns null, where to place the resource file?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After trying to access ivars using KVC, I have noticed that there was no
I have the following schema.yml file: Page: actAs: I18n: fields: [name,html,urlShortDesc] columns: name: string
I'm trying to load i18n properties file via core:bundle-names tag in seam components.xml conf
I'm trying to access some related entities using navigation properties. I've turned off Lazy
Trying to access a Servlet from a button on HTML page //Html Page FORM
Am trying to access an API using CURL I can access the API from
I'm trying to access a samba share that requires authentication. I do not want
I have been trying to access an HTTPS URL with the HTMLUnitDriver API of
trying to access various properties of my video tag. started looking at the HTML5
Im trying to access ValidationMessage through jquery. I have <%: Html.TextBox(vcr_LinkAddress,null, new { maxlength

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.