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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:21:23+00:00 2026-06-12T02:21:23+00:00

I am trying to load a class whose name is specified in a properties

  • 0

I am trying to load a class whose name is specified in a properties file. Here is the code for the same.

try {
    Properties properties = new Properties();   
    InputStream in = MyAbstractFactory.class.getResourceAsStream("/some.properties");
    properties.load(in);
    String impl = properties.getProperty("key");
    MyAbstractFactory factories = (MyAbstractFactory) Class.forName( impl ).newInstance();
    return factories;
} catch (Exception e) {
    return new DefaultFactoriesImpl();
}

This code is part of a jar file. the properties file is just outside the jar. Its unable to load the properties file and is loading DefaultFactoriesImpl instead. I know this happens when MyAbstractFactory.class.getResourceAsStream cant find the resource in the class path but that doesn’t seem to be the case here.

Dir Structure:-

  • com
  • myjar.jar
  • some.properties

Command i am executing is “java -jar myjar.jar”

Any feedback on why this might be happening. Could this have something to do with Clasloaders? I’d like to add that when i run this code from within eclipse it seems pick up some.properties just fine.

  • 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-12T02:21:24+00:00Added an answer on June 12, 2026 at 2:21 am

    Remove the leading slash from the argument you pass to getResourceAsStream().

    Put the folder outside the JAR into the CLASSPATH when you execute the JAR. I don’t know if the manifest CLASSPATH overrides the one you might pass using -cp. Play with it; one of them will work.

    It’s not finding your .properties file because it’s not in the JVM CLASSPATH. When you do it properly, the JVM will find it.

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

Sidebar

Related Questions

I'm getting a cross domain error when trying to load a custom class. Here
I'm trying to load dynamically a class contained in a .jar file. I know
I'm trying to load text of all divs that have a particular class into
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
Trying to load a small .txt file into mysql but get all my data
I trying to load and save setting with this code but when I closing
Ok, here is the code and then the discussion follows: public class FlatArrayList {
Is it possible to load a class in Java and 'fake' the package name/canonical
I'm trying to load a customized spree page by inheriting from Spree::BaseController. class PagesController
I have a problem with out of memory when I'm trying load a few

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.