Results 1 to 2 of 2
  1. #1
    esolve is offline Member
    Join Date
    Mar 2015
    Rep Power

    Default How to read resource files in a jar?

    I have two modules A and B. I package A as a jar and B use this jar as library.
    A has a property file and it has a property cache which read the key-value pairs in

    InputStream in = PropertyCache.class.getResourceAsStream("/");
    Properties prop = new Properties();
    try {
    Iterator<String> it = prop.stringPropertyNames().iterator();
    while (it.hasNext()) {
    String key =;
    PROPERTIES.put(key, prop.getProperty(key));

    when A runs in its own, it is OK. But if I use it as a third-party jar in B, this doesn't work coz getResourceAsStream() uses the classpath of B, not A.
    so in my casse, what can I do?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: How to read resource files in a jar?

    I'm not sure I understand the configuration of your project.
    Can you describe the locations of the files being used? What jar file are the resources in and what jar file is the code/class that is trying to access those resources?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2017, 12:24 AM
  2. Accessing resource files within JAR
    By Dissonance in forum Java Applets
    Replies: 17
    Last Post: 06-22-2012, 02:02 AM
  3. Replies: 2
    Last Post: 06-11-2011, 01:54 PM
  4. Runnable jar does not include my resource files
    By owboateng in forum Eclipse
    Replies: 2
    Last Post: 05-09-2011, 01:54 PM
  5. Files, cannot read!
    By LennyKosmos in forum New To Java
    Replies: 2
    Last Post: 10-02-2010, 01:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts