How to use maven resources also as test resources

前端 未结 2 1557
深忆病人
深忆病人 2020-12-17 18:00

I have a maven project that loads an xslt file and executes the transformation along with other processing on the result. Normally when the user runs the application, the us

2条回答
  •  醉梦人生
    2020-12-17 18:10

    If you put a file foo.txt inside src/test/resources/, you can open this via:

    // try-with-resource (Java 1.7)
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("foo.txt")) {
        // do something with is...
    }
    

    You can also take a look at the maven-resources-plugin.

提交回复
热议问题