How to access resource using class loader in Java 9

From ClassLoader.getResource JavaDoc:

Resources in named modules are subject to the encapsulation rules specified by Module.getResourceAsStream. Additionally, and except for the special case where the resource has a name ending with “.class”, this method will only find resources in packages of named modules when the package is opened unconditionally (even if the caller of this method is in the same module as the resource).

So, to fix your issue, you should make the package css open:

module pk.training.basit {
    exports pk.training.basit;
    requires transitive javafx.controls;
    opens css;
}

Leave a Comment