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

  • Home
  • SEARCH
  • 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 9073537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:26:26+00:00 2026-06-16T18:26:26+00:00

In my (non Android test) test I placed a resource called common.properties in src/main/resources

  • 0

In my (non Android test) test I placed a resource called common.properties in src/main/resources into my Android project to read the Maven project version from it:

@Test
public void testReadVersion() throws IOException {      
    Properties props = new Properties();
    props.load(FileUtils.openInputStream(FileUtils.toFile(this.getClass().getResource("/common.properties"))));

    String version = props.getProperty("version");

    assertNotNull(version);
    assertTrue(!"".equals(version));
}

This works.
But when I try to access the same resource in production code, I always get NullPointerExceptions when accessing the resource:

    Properties props = new Properties();
    final StringBuilder versionBuilder = new StringBuilder();

    try {
        props.load(FileUtils.openInputStream(FileUtils.toFile(this.getClass().getResource("/common.properties"))));

        versionBuilder.append(props.getProperty("version"));
    } 
    catch (IOException e) {
        // will be ignored.
    }

I debugged it. It’s null because it doesn’t find the resource. How should I solve this? When I place the file into res/raw to read it by

props.load(getResources().openRawResource(R.raw.common));

the file access works, but it cannot translate the value from my file content: version=${project.version}.
The result would be the value string itself ${project.version} and not Version 1.0 or something. What are my options?

[UPDATE]
The solution accepted below doesn’t work in my latest project anymore. I always get ${project.version} instead of the value. Don’t know why this is so. Not even the solution with AssetManager works for me. I found a good workaround which is less inconvenient too. I fetch and display the information of android:versionName (AndroidManifest).

String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;

TextView version = (TextView)findViewById(R.id.version);
version.setText(" " + versionName);
  • 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-16T18:26:28+00:00Added an answer on June 16, 2026 at 6:26 pm

    First i would suggest to use a simpler approach:

    InputStream resourceAsStream = this.getClass().getResourceAsStream("/common.properties");
    Properties prop = new Properties();
    prop.load(resourceAsStream);
    

    which will work either if you running in your tests or in production code.
    Furthermore to get values from the pom replaced within your resources you have to setup a filtering:

    <project>
      ...
      <build>
        ...
        <resources>
          <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
          </resource>
          ...
        </resources>
        ...
      </build>
      ...
    </project>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Android project that depends on a non-Android JAR that contains resources
I'm trying to import a non-android project into my android-project in eclipse. I've tried
I have problems with adding a non-android xml file init.xml to android project in
Does anyone have any experience with pjsip on android devices? I see several non-commercial/test
I am writing junit test cases for an android project. I wrote junit for
I am trying to push non-english file name into the phone(android 2.3.3), but get
I'm new to android programming. I'm trying to include code from a non-android project
Subject of discussion: User security on non rooted Android phones. Is it possible to
I try to make an Android application which communicates with a non-standard ISO15693 (NFC-V)
I am trying to download a non-market application in Android using the DownloadManager class.

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.