Cannot read resources in Java 9 module (JPMS)
Answered
Hello everyone,
I try to migrate from Eclipse (and I have to say, I really appreciate Intellij for now), but I have some trouble accessing resources in a Java 9 module environment.
I can run my projects with Eclipse or Gradle, but something doesn't work when I run it with Intellij (right click on main class, and "Run Main").
As requested by the javadoc, the package containing the resource is opened.
To read my files, I'm using:
module.getResourceAsStream()
I tried some configuration, but I'm not able to solve it for now.
I made a test project to reproduce the problem (I simply use the gradle import):
https://github.com/Ealrann/testJPMSResource
What do I miss? Maybe Intellij simply doesn't support JPMS resources ?
Please sign in to leave a comment.
Is it the error you are speaking about:
https://i.imgur.com/tGhry66.png
I tried to run it via Gradle from the console and the same error returns. So, I suppose it is hardly related to IntelliJ IDEA.
Indeed, but it's working on my console when I do a `git clone` and a
./gradlew run
https://imgur.com/n6xOHgn
This test project is a basic use of resource with Java 9 (Well, maybe I missed something?), but I need to use resources in a modular (Jigsaw) way. Maybe I have to configure something in Intellij to do so?
May you show your run/debug configuration (https://i.imgur.com/eLJqDSu.png)?
Yes, that's how I work for now. But it's really unpractical mainly because the debug mode of gradle is really slow (my project is big), I'm loosing time with it. That's why I'd like to use the debugger of IJ.
Edit: Oh sorry, I miss read. I'll post what you ask soon.
So, here the screenshots.
This one with gradle is working and allow me to debug, but as I said earlier, it's really slow to debug with it on my full projects:
https://imgur.com/YGS82qH
And meanwhile, using the IJ run configuration doesn't work:
https://imgur.com/a/glAuGEW
Hello,
I found that gradle doesn't support for JPMS https://stackoverflow.com/questions/51864473/where-do-resource-files-go-in-a-gradle-project-that-builds-a-java-9-module/51921521#51921521 and maybe that is the issue.
Maybe one solution for this problem in intellij idea; this config generate the class and resources in the same folder. It works in Intellij 2019.3.3 and Java 11.
idea {module {
inheritOutputDirs = false
outputDir = compileJava.destinationDir
testOutputDir = compileTestJava.destinationDir
}
}
Here is related issue to track: https://youtrack.jetbrains.com/issue/IDEA-197469
Thank you all !