Where do resource files go in a Gradle project that builds a Java 9 module?

后端 未结 2 1779
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 13:06

As of IDEA 2018.2.1, the IDE starts error-highlighting packages \"not in the module graph\" from dependencies that have been modularized. I added a module-info.java

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 13:21

    Beside @Slaw's answer (thanks to him), I had to open the package that contains the resources to the caller's module. As follows (moduleone.name module-info.java):

    opens io.fouad.packageone to moduletwo.name;
    

    Otherwise, the following would return null:

    A.class.getResource("/io/fouad/packageone/logging.properties");
    

    considering that class A is in module moduletwo.name and the file logging.properties is inside module moduleone.name.


    Alternatively, moduleone.name could expose a utility method that returns the resource:

    public static URL getLoggingConfigFileAsResource()
    {
        return A.class.getResource("/io/fouad/packageone/logging.properties");
    }
    

提交回复
热议问题