/** * Load resource. * * @param configurationResourceName * the configuration resource name * @return the uRL */ private URL loadResource(String configurationResourceName) { ClassLoader standardClassloader = ClassLoaderUtil.getStandardClassLoader(); URL url = null; if (standardClassloader != null) { url = standardClassloader.getResource(configurationResourceName); } if (url == null) { url = this.getClass().getResource(configurationResourceName); } log.info("Creating EhCacheFactory from a specified resource: " + configurationResourceName + " Resolved to URL: " + url); if (url == null) { log.warn("A configurationResourceName was set to {} but the resource could not be loaded from the classpath.Ehcache will configure itself using defaults." ,configurationResourceName); } return url; }
/** * Load a resource from the classpath. */ protected static URL loadResource(String configurationResourceName) { ClassLoader standardClassloader = ClassLoaderUtil.getStandardClassLoader(); URL url = null; if (standardClassloader != null) { url = standardClassloader.getResource(configurationResourceName); } if (url == null) { url = AbstractEhcacheRegionFactory.class.getResource(configurationResourceName); } LOG.debug("Creating EhCacheRegionFactory from a specified resource: {}. Resolved to URL: {}", configurationResourceName, url); if (url == null) { LOG.warn("A configurationResourceName was set to {} but the resource could not be loaded from the classpath." + "Ehcache will configure itself using defaults.", configurationResourceName); } return url; }
/** * Load the supplied resource from the classpath. */ protected URL loadResource(String configurationResourceName) { ClassLoader standardClassloader = ClassLoaderUtil.getStandardClassLoader(); URL url = null; if (standardClassloader != null) { url = standardClassloader.getResource(configurationResourceName); } if (url == null) { url = this.getClass().getResource(configurationResourceName); } LOG.debug("Creating EhCacheProvider from a specified resource: {}. Resolved to URL: ", configurationResourceName, url); if (url == null) { LOG.warn("A configurationResourceName was set to {} but the resource could not be loaded from the classpath." + "Ehcache will configure itself using defaults.", configurationResourceName); } return url; } }
/** * Load the given class by name * * @param className a fully qualified class name * @return Class the loaded class * @throws ClassNotFoundException if the class cannot be loaded * @since 1.7 */ public static Class loadClass(String className) throws ClassNotFoundException { Class clazz; try { clazz = Class.forName(className, true, getStandardClassLoader()); } catch (ClassNotFoundException e) { //try fallback clazz = Class.forName(className, true, getFallbackClassLoader()); } return clazz; }
private static SizeOfFilter getUserFilter() { String userFilterProperty = System.getProperty(USER_FILTER_RESOURCE); if (userFilterProperty != null) { List<URL> filterUrls = new ArrayList<URL>(); try { filterUrls.add(new URL(userFilterProperty)); } catch (MalformedURLException e) { LOG.debug("MalformedURLException using {} as a URL", userFilterProperty); } try { filterUrls.add(new File(userFilterProperty).toURI().toURL()); } catch (MalformedURLException e) { LOG.debug("MalformedURLException using {} as a file URL", userFilterProperty); } filterUrls.add(ClassLoaderUtil.getStandardClassLoader().getResource(userFilterProperty)); for (URL filterUrl : filterUrls) { SizeOfFilter filter; try { filter = new ResourceSizeOfFilter(filterUrl); LOG.info("Using user supplied filter @ {}", filterUrl); return filter; } catch (IOException e) { LOG.debug("IOException while loading user size-of filter resource", e); } } } return null; }
/** * Configures a bean from an XML file in the classpath. */ public static Configuration parseConfiguration() throws CacheException { ClassLoader standardClassloader = ClassLoaderUtil.getStandardClassLoader(); URL url = null; if (standardClassloader != null) { url = standardClassloader.getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE); } if (url == null) { url = ConfigurationFactory.class.getResource(DEFAULT_CLASSPATH_CONFIGURATION_FILE); } if (url != null) { LOG.debug("Configuring ehcache from ehcache.xml found in the classpath: " + url); } else { url = ConfigurationFactory.class.getResource(FAILSAFE_CLASSPATH_CONFIGURATION_FILE); LOG.warn("No configuration found. Configuring ehcache from ehcache-failsafe.xml " + " found in the classpath: {}", url); } Configuration configuration = parseConfiguration(url); configuration.setSource(ConfigurationSource.getConfigurationSource()); return configuration; }
final ClassLoader contextClassLoader = ClassLoaderUtil.getStandardClassLoader(); final URL configUrl = contextClassLoader.getResource(file);