On 7 February 2018 at 16:35, Alan Bateman <alan.bate...@oracle.com> wrote: > On 07/02/2018 14:23, Stephen Colebourne wrote: >> >> I've been trying to use ClassLoader.getResources(String). The entire >> application is in one named module, this includes the code that >> invokes the ClassLoader method and the resource that it is trying to >> find. > > Can you summarize what you are trying to do? If this is code in a module > trying to locate one of its own resources then Class.getResourceXXX or > Module.getResourcAsStream are the candidate APIs to use (not > ClassLoader.getResourceXXX as that can never locate resources that are > encapsulated).
I was using maven to create a jar-with-dependencies file, so I could use jlink. With all the code in one jar file, there shouldn't be any access barriers to worry about. ClassLoader.getResources(String) worked just fine until Java 9. The two APIs are not comparable - the ClassLoader one returns all URLs found, whereas the Class one returns just one URL. Switching API would change behaviour. The code can be seen here: https://github.com/OpenGamma/Strata/blob/master/modules/collect/src/main/java/com/opengamma/strata/collect/io/ResourceConfig.java#L242 It is a core part of the system that loads configuration at startup. thanks Stephen