Adding resources in IntelliJ for Maven project

后端 未结 7 1268
走了就别回头了
走了就别回头了 2020-11-28 07:36

I have a project structure like this:

src
 |-main
    |-java
       |-com.abc.xyz
          |-Login.java

I have to add a resource file to t

相关标签:
7条回答
  • 2020-11-28 08:16

    No..... the structure is wrong.... you should not create the same package under resources, that is ugly and not proper: resources is for resources, and should not contain source packages.

    When using ClassLoader.getResources(asStream)(path) method, the method just starts searching from the root of the classpath and the path name cannot start with / as leading characters. What you have to do, is to mark the resources as resources folder in IntelliJ. Then the files under resources will be listed under classpath and you can easily use them like you have done.

    (I see in previous answers this option is not available yet in 2013, you only have mark as source folder, just like in Eclipse till now we have "add source folder", but now in 2018 it is available in Intellij: you can mark a folder as source, resources, test source, test resources, and all of them will be add to the root of classpath. )

    0 讨论(0)
提交回复
热议问题