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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:06:55+00:00 2026-06-05T01:06:55+00:00

Here is the Maven structure of my project app > common-module > webapp-module >

  • 0

Here is the Maven structure of my project

app
  > common-module
  > webapp-module
  > batch-module
 pom.xml

The common-module exposes a Version class. This class is used by both webapp and batch modules.

The Version class has one unique static method called get. It returns the global version of the project.

The global version is stored in a properties file. When get is called from batch module (a standalone java application), the properties file is successfully loaded.

In the webapp, things are different. I have created a managed bean VersionBean that would permit any JSF page to call the get method. Whenever I use one of the following

FacesContext.getCurrentInstance().getExternalContext()

FacesContext.getCurrentInstance().getExternalContext().getContext()

Thread.currentThread().getClassLoader()

I can never find the properties.file.

How can I load the properties file (getResourceAsStream) located in a jar file from a managed bean ?

EDIT
Here is the solution I came up with based on advice from @BalusC and @eljunior

VersionBean.java

@ManagedBean(eager=true)
@ApplicationScoped
public class VersionBean {
    private String version;
    @PostConstruct
    public void init(){
        version = Version.get();
    }
}

Version.java

public class Version {
    public static String get() {
        InputStream is = Version.class.getResourceAsStream("/version.properties");

        // Read InputStream and return version string ...
    }
}
  • 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-05T01:06:56+00:00Added an answer on June 5, 2026 at 1:06 am

    I would delegate the loading of the properties file to the same classloader of the class Version: in the method get, use Version.class.getResourceAsStream("yourFile.properties");.

    That should work anywhere the Version class can be loaded, so it would work in the webapp too (of course, provided the properties file actually IS inside the common-module jar file :).

    Then your VersionBean could be an application scoped bean that just loaded the property on initializing the application, something like this:

    @ManagedBean(eager=true)
    @ApplicationScoped
    public class VersionBean {
        private String version;
        @PostConstruct
        public void init(){
            version = Version.get();
        }
    }
    

    Note that if you are using a JSF version before 2.0, you’ll have to configure the managed-bean in the faces-config.xml instead of using the annotations @ManagedBean and @ApplicationScoped.

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

Sidebar

Related Questions

This is the directory structure of the project (maven2 is used): pom.xml /src /main
I have a Maven project structured like this: src/main/java/test/App.java src/main/resources/config/message.txt Inside App.java, I have
Currently, I have the following structure for my project Foo : foo-parent +- pom.xml
Here is my maven project structure ProjectParent -Class1 -Class2 -Module1 (another sub directory) --Module1Class1
I'm using a maven plugin for install4j in my project, located here . That
here is the structure of my project. proj ---src ----main ----java ----Main.java ----resources ----res.txt
I am trying to setup a small maven based project structure as follows Maven
http://maven.apache.org/pom.html#Properties says property values are accessible anywhere within a POM. Should this read are
i have a problem with tomcat-maven-plugin : here's the code <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>tomcat-maven-plugin</artifactId> <version>1.0-beta-1</version>
Quite new to maven here so let me explain first what I am trying

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.