Accessing resource files in a java jigsaw module

Viewed 788

I'm trying to access a file in my eclipse project from a class within the project. I need to declare the project as a jigsaw module to reach it from other projects, however by doing this, I no longer have access to files like "example.png" within the project.

This is my project structure:

project/
  module-info.java
  src/
    ...                   # trying to access files from here
  rsc/
    icons/
      example.png         # this is the file I need
    other-example.png

My module-info.java looks like this:

module dice_engine {
    exports com.packages.in.src;

    requires java.desktop;
    requires java.logging;
    requires javafx.graphics;
    requires javafx.controls;
}

And I try reading the file like this:

getClass().getClassLoader().getResourceAsStream("icons/example.png")

Note that

  1. I added the rsc directory as a source-folder to build path in eclipse
  2. This was possible before creating the module-info.java
  3. other-example.png is still accessible
0 Answers
Related