1

I have two projects: A project B project (lists A as one of B's dependencies)

A has a method that relies on A's resource

When B calls A's method, A ends up access B's resource folder and thus is unable to find A's own resource files.

Any way around this?

Bolto Cavolta
  • 413
  • 1
  • 8
  • 16
  • You should load the resources via this.getResourcesAsStream("/name-of-a.properties");... – khmarbaise Sep 29 '16 at 05:13
  • This might help you - http://stackoverflow.com/questions/7095539/how-can-my-project-access-its-resources-directory-both-when-run-in-eclipse-and – Afgan Sep 29 '16 at 07:23

1 Answers1

0

In order to ensure that a project will always access its own resources, you need to load them using the Class#getResource method.

Example:

public class MyCalledClass{
    public static void loadResource() {
        new File(MyCalledClass.class.getResource("file.txt").getPath()); // Will retrieve the file called "file.txt"
                                                                         // in the project where this class is

        new File("file.txt");  // Will retrieve the file called "file.txt" in the project calling this method
    }
}
William A.
  • 425
  • 5
  • 14