How should I discover test-resource files in a Maven-managed Java project?

后端 未结 4 1149
北恋
北恋 2021-02-13 21:06

I have a project that uses the normal Maven structure, e.g.

module
\\ src
  \\ main
    - java
    - resources
  \\ test
    - java
    - resources
4条回答
  •  野性不改
    2021-02-13 21:28

    Just for completeness, wanted to point out the way to get this without having to grab the current instance of the ClassLoader, using ClassLoader#getSystemResource. This example does the work without having to place a file at the top.

    //Obtains the folder of /src/test/resources
    URL url = ClassLoader.getSystemResource("");
    File folder = new File(url.toURI());
    //List contents...
    

提交回复
热议问题