WildFly - getting resource from WAR

后端 未结 7 700
既然无缘
既然无缘 2020-12-21 00:13

I am using the following method to get a resource from WAR file in WildFly:

this.getClass().getResource(relativePath)

It works when the app

相关标签:
7条回答
  • 2020-12-21 00:59

    We had a similar problem and our fault was that we tried to access the static resource through the raw path instead of using the input stream the resource is providing - the following code works for us even when deploying a non-exploded .war-file.

    final URL resource = this.getClass().getResource(FILE);
    
    try (final InputStream inputStream = resource.openStream();
         final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
         final BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
        // Use bufferedReader to read the content
    } catch (IOException e) {
        // ...
    }
    
    0 讨论(0)
提交回复
热议问题