Reloading resources loaded by getResourceAsStream

后端 未结 3 1681
無奈伤痛
無奈伤痛 2021-02-13 23:44

Following best practices, I\'m using Thread.currentThread().getContextClassLoader().getResourceAsStream to load resources in a web application (like text files or x

相关标签:
3条回答
  • 2021-02-14 00:06

    Try this:

    ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
    URL resURL = ctxLoader.getResource(resName);
    URLConnection resConn = resURL.openConnection();
    resConn.setUseCaches(false);
    InputStream resIn = resConn.getInputStream();
    ...
    
    0 讨论(0)
  • 2021-02-14 00:19

    i finally solved this problem by change the jar file name, every time i change the resource content, i change a new name with current timestamp

    0 讨论(0)
  • 2021-02-14 00:21

    In addition to kschneid's answer which might work for Tomcat indeed, I wanted to add that for JBoss AS 5+ it already seems to work without needing any special tricks.

    Caching of resources is probably class loader specific. The JBoss AS one either doesn't cache or is smart enough to see that the resource on disk has changed.

    0 讨论(0)
提交回复
热议问题