I have the following project structure.
ProjectName
|
|---src
|
|---main
|
|---java
| |
| |---ModuleName
| |
| |---module-info.java
| |
| |---PackageName
| |
| |---Main.java
|
|---resources
|
|---ResourceParentFolder
|
|---ResourceSubFolderA
| |
| |---Resource1A.png
| |---Resource2A.png
| |---Resource3A.png
|
|---ResourceSubFolderB
|
|---Resource1B.png
|---Resource2B.png
|---Resource3B.png
I have a shell script that compiles the code, and then runs that code.
javac \
--module-source-path="src/main/java" \
--module=ModuleName \
-d classes
java \
--module-path="classes;src/main/resources" \
--module=ModuleName/PackageName.Main
I also have a shell script that turns my compiled code into a modular jar, and then runs that jar.
jar \
--verbose \
--create \
--file run/executable/jar/ProjectName.jar \
--main-class PackageName.Main \
-C classes/ModuleName . \
-C src/main/resources .
java \
--module-path="run/executable/jar" \
--module=ModuleName/PackageName.Main
In my main method, I have a call to java.lang.module.ModuleReader
, specifically to its list() method, that allows me to traverse my module and its contents.
I am able to see the contents of my ResourceParentFolder
if I take my jar file and try to run it, but the call to list()
only returns the .class
files when I am only running my compiled code. Is this because my module is misconfigured? Or is this simply unsupported functionality?
Again, ModuleReader.list()
returns a recursive list of the contents of my source code and my resource folder when run as a jar, but it only returns the source code when run as compiled code. How do I get the compiled code to also populate the ModuleReader.list()
? Or is that just not supported functionality unless it is in a jar or something?
And to be clear, I am well aware that there are a million and one other ways to fetch a resource. But I want to know if it is possible to do it the way I requested above. And if not, then why?
EDIT -- detailing some of my failed attempts.
I tried copying the src/main/resources
directory into classes
, the location of my module before it turns into a jar. Unfortunately, nothing got picked up by it.
I also tried to do --patch-modules
, but that also failed, but with an error.
error: no source files
Here is the command that I used.
javac --patch-module ModuleName=src/main/resources