I have two project where one is depended on the other, i.e. project A depends on project B, and the two projects reside in different directories.
In the independent project, i.e. project B, there is a class which holds a code that tries to access directories and files with respect to independent project directory. Since the depended project, i.e. project A, instantiate an object from the independent project, when the object execute System.getProperty("user.dir") it returns the execution directory, i.e. the directory of the dependent project; the same holds for new File(".").getAbsolutePath().
I would like to solve the issue in generic way, i.e. I wish to avoid the need to pass as an argument the path, rather, I wish the use relative directories programatically.
Any guidance\clues?
P.S. not sure if it is relevant, but I am using Eclipse as my IDE.
UPDATE
This should hold…
final String clsName = getClass().getName() + ".class";
System.out.println(getClass().getResource(clsName));
I’d use the class-loader instead of using paths directly. In eclipse, and in an deployment situation both projects resources should be in the classpath.
Something like this should be able to load a resource from either project A or B.