getClass().getResourceAsStream() in maven project

前端 未结 3 741
轻奢々
轻奢々 2021-02-18 20:58

The pom.xml of my maven project looks as follows:



        
3条回答
  •  一向
    一向 (楼主)
    2021-02-18 22:01

    I was facing this same problem.

    When you are trying to get the resource like this:
    getClass().getResourceAsStream("test")

    You are trying to find the resource relative to that package.

    To get the resource from the src/main/resources directory, you have to put a slash before the resource name.
    getClass().getResourceAsStream("/test")

提交回复
热议问题