Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Class.getResource and ClassLoader.getResource are the APIs to obtain resource files associated with the class and/or classloader. An example in the JDK: ResourceBundle.getBundle finds the caller's class and uses the caller class loader to load a resource bundle. Libraries and frameworks such as Groovy, Log4j need similar capability and also need the ability to filter their implementation classes. Existing code has been using sun.reflect.Reflection.getCallerClass(int depth). There is no current way for libraries to support loading resource files on behalf of its immediate caller without explicitly passing the calling Class (for example localization data in GUI applications). See discussion in [1]. [1] http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-June/018353.html
|