Hm, so how can ClassA access the resource from module com.b directly - without having a class instance of module b?

-Wolfgang

On 18/05/2017 08:16, wzberger wrote:

:

public class ClassA{
  public ClassA() {
    //success
System.out.println(getClass().getResource("/com/b/resources/test.txt"));
The test creates an instance of ClassB (extends ClassA) and so getClass() returns ClassB here, not ClassA. So when constructing a ClassB then this is equivalent to ClassB.class.getResource(...).


    //fail - null
System.out.println(ClassA.class.getResource("/com/b/resources/test.txt"));
Right, as this resource is not in the com.a module. Change this to ClassB.class.getResource(...) and it should work.

-Alan



Reply via email to