Reputation: 3798
Instead of writing everything in question I would like to place an image. The problem is where should I place the resource directory which contain the .properties
files?
See the image for more information and exact problem.
Upvotes: 3
Views: 5019
Reputation: 5417
This is a known bug in intellij. For some unknown reason, it is pending forever
https://youtrack.jetbrains.com/issue/IDEA-197469
Upvotes: 0
Reputation: 464
First of all, if you are using Intellij IDEA and Gradle, try adding this to your build.gradle
:
apply plugin: 'idea'
idea {
module {
inheritOutputDirs = true
}
}
The more likely solution
From my experience Java 9 has locked down accessing resources based on some rules about whether the resource is encapsulated or not (see javadocs).
Things that have worked for me:
Putting a resource in the root of my resources folder and calling
getClass().getClassLoader().getResource("myresource.txt")
Making the folder structure leading to your resource match a suitable package in your project. For example, if you had a com.your.package then your folder structure would be resources/com/your/package/myresource.txt. Once your had this, you can add opens com.your.package
in module-info.java and get your resource by calling
YourClass.class.getResource("/com/your/package/myresource.txt")
Other things to try
Marking your resources folder as resources in Intellij IDEA.
Upvotes: 6
Reputation: 1
I faced similar issue while reading property files from modular jar. I placed the property files outside the jar and specified the location of property files as class-path. It worked fine. My Java version is as follows: Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
Upvotes: 0