getResourceAsStream returns null

前端 未结 16 2334
臣服心动
臣服心动 2020-11-22 04:00

I\'m loading a text file from within a package in a compiled JAR of my Java project. The relevant directory structure is as follows:

/src/initialization/Life         


        
16条回答
  •  误落风尘
    2020-11-22 04:44

    I found myself in a similar issue. Since I am using maven I needed to update my pom.xml to include something like this:

       ...
    
    
        
            
                /src/main/resources
            
            
                ../src/main/resources
            
        
        
            ...
    

    Note the resource tag in there to specify where that folder is. If you have nested projects (like I do) then you might want to get resources from other areas instead of just in the module you are working in. This helps reduce keeping the same file in each repo if you are using similar config data

提交回复
热议问题