Accessing resource files in a java jigsaw module [duplicate]
Asked Answered
T

0

4

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
Tether answered 13/11, 2018 at 16:52 Comment(1)
By the way I suppose the compiler doesn't include packages without .java files when building the module (Although that doesn't explain why it worked when it wasn't a module). My question is just: What is the correct way to read the file then?Tether

© 2022 - 2024 — McMap. All rights reserved.