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?

- 3,658
- 4
- 44
- 80
-
Is your project a named module? Also, what if you remove that `/` from the inputStream name? On a side note sharing reproducible code is better than the screenshot. – Naman Feb 08 '18 at 01:24
-
2The location in the project doesn't matter to the module system. However, its location in the output directory is really important. It needs to be in the same directory tree as the class files. If it's not then the IDE needs to patch the module to add the resources. If you are creating a modular JAR then the resources need to be in the same JAR file as the class files. As regards the resource name then "/abc.properties" is correct for the case that the resource is in the top-level directory of the module. – Alan Bateman Feb 08 '18 at 06:31
-
@AlanBateman then why I'm not able to access? where should I place the resource directory? – Asif Mushtaq Feb 08 '18 at 06:59
-
@nullpointer I don't know about the project named module, I was struggling with the IDEA to create java 9 project. And I even tried by removing `/` – Asif Mushtaq Feb 08 '18 at 07:03
-
1Again, the important thing is to understand where the resources are in the output directory. If they are in the same tree as the compiled classes then Class.getResourceXXX will locate them. It cannot locate resources in locations that are not part of the module. – Alan Bateman Feb 08 '18 at 10:58
-
Here is the structure of output https://imgur.com/a/EMiZ8 and output have production folder then again there three modules as climesoft.data climesoft.main climesoft.net – Asif Mushtaq Feb 08 '18 at 12:28
-
This isn’t even remotely related to Java 9. It’s about how you configure your IDE to include the resources in you build. You get into the same problem with previous Java versions. – Holger Feb 09 '18 at 10:45
-
@Holger would you like to suggestion any article which help me to solve such problem? mean how the project structure should be for different IDEA? or even for command line. – Asif Mushtaq Feb 09 '18 at 16:27
3 Answers
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 callingYourClass.class.getResource("/com/your/package/myresource.txt")
Other things to try
Marking your resources folder as resources in Intellij IDEA.

- 454
- 5
- 15
-
1This "inheritOutputDirs = true" solution fixed my problem running JavaFX 11 in IntelliJ IDEA within a Gradle project. – Trisha Oct 11 '18 at 15:58
-
I just quickly wanted to add that "inheritOutputDirs" lets Gradle put resource files in the same location as the class files in the final output folder, instead of maintaining the separate resources structure. – Christian May 02 '19 at 15:48
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)

- 1
- 3
This is a known bug in intellij. For some unknown reason, it is pending forever

- 5,327
- 8
- 41
- 50