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 ?

 

0
8 comments

Is it the error you are speaking about: 

Exception in thread "main" java.lang.NullPointerException
at java.base/java.io.Reader.<init>(Reader.java:167)
at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:72)
at testJPMS/test.Main.main(Main.java:14)

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. 

0
Avatar
Permanently deleted user

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?

0
Avatar
Permanently deleted user

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.

0
Avatar
Permanently deleted user

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 

 

0
Avatar
Permanently deleted user

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
}
}
3
Avatar
Permanently deleted user

Thank you all !

0

Please sign in to leave a comment.