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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:24:09+00:00 2026-06-10T17:24:09+00:00

I have a properties file that I’ve included within a jar I’ll be distributing.

  • 0

I have a properties file that I’ve included within a jar I’ll be distributing. Before I decided to include the file within the jar I was loading it like

properties.load(new FileInputStream(configFileName));

But this stopped working once the file was placed inside the jar so I changed the code to

properties.load(MyClass.class.getResourceAsStream(configFileName));

Only problem is I have unit tests that use my properties (which are loaded statically so I can’t mock it). The unit tests are run before the jar is made so they all fail now. Is there an elegant way to handle a file that will be in a jar only if the program is run as a jar?

  • 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-10T17:24:11+00:00Added an answer on June 10, 2026 at 5:24 pm

    the problem probably is that this file is not visible to your classloader..

    i’d use this

    Classloader cl = getClass().getClassloader();
    properties.load(cl.getResourceAsStream(configFileName))
    

    pay attention to your classload if this app is a webapplication.. you’ll have many classloaders on this case.. your resource must be visible to this classloader..
    in a servlet container like tomcat they work this way

      Bootstrap
          |
       System
          |
       Common
        /     \
    Webapp1   Webapp2 ... 
    

    you can read more here
    http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

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

Sidebar

Related Questions

I have an executable jar Client.jar that requires jndi.properties file. Since the jndi properties
I have an ant properties file that looks like this (although I can adjust
I have a properties file, let say my-file.properties. In addition to that, I have
I have an f:loadBundle that loads a properties file from my classpath. <f:loadBundle basename=com.xxx.ui.messages
I have configured the loading of the properties file as shown below (Spring 3.1)
We have a .properties file that has some values persisted as JSON. I keep
In my properties file that I have for a mod I'm making for Minecraft
In GWT, you can have a .properties file that lists key value pairs: foo
I have a property in my Messages.properties file that has an argument that uses
I have an application that uses a properties file that was added by hand

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.