Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

Java 9 Module system Resources files location

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. Java 9 Resource Directory

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

  1. Putting a resource in the root of my resources folder and calling

    getClass().getClassLoader().getResource("myresource.txt")

  2. 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.

Intellij marking folder as resources


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...