How to load resources from base module
wzberger
javadevlist at javasoft.de
Thu May 18 07:16:28 UTC 2017
Here is a simple example which demonstrates the issue - still something
missing?
//------------ MODULE A
module com.a {
exports com.a;
}
package com.a;
public class ClassA{
public ClassA() {
//success
System.out.println(getClass().getResource("/com/b/resources/test.txt"));
//fail - null
System.out.println(ClassA.class.getResource("/com/b/resources/test.txt"));
}
}
//------------ MODULE B
module com.b {
requires com.a;
exports com.b;
opens com.b.resources to com.a;
}
package com.b;
import com.a.ClassA;
public class ClassB extends ClassA{
public ClassB(){
}
}
//------------ MODULE C
module com.c {
requires com.a;
requires com.b;
}
package com.c;
import com.b.ClassB;
public class ModuleTest{
public static void main(String[] args){
new ClassB();
}
}
-Wolfgang
> On 17/05/2017 18:22, wzberger wrote:
>
>> The resources are mainly images and XML files, located in separate
>> packages. By adding the opens clause it works fine for Class B
>> (called from module a) - however, it does not work for Class A
>> (returns null). I wonder if this is the intended behavior?
> I'm not aware of any bugs in this area. Can you expand a bit more on
> "returns null" case. If the packages are open as you say then code in
> both `a` and `b` should be able to locate the resources in `b`.
>
> -Alan
>
>
More information about the jigsaw-dev
mailing list