Loading same-name resource from multiple JARs
suggest changeResources with the same path and name may exist in more than one JAR file on the classpath. Common cases are resources following a convention or that are part of a packaging specification. Examples for such resources are
- META-INF/MANIFEST.MF
- META-INF/beans.xml (CDI Spec)
- ServiceLoader provider-configuration files, which list implementation classes
To get access to all of these resources in different JARs, one has to use a ClassLoader, which has a method for this. The returned Enumeration can be conveniently converted to a List using Collections.list.
Enumeration<URL> resEnum = MyClass.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
ArrayList<URL> resources = Collections.list(resEnum);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents