Java Code Examples for cn.hutool.core.util.ClassLoaderUtil#getClassLoader()
The following examples show how to use
cn.hutool.core.util.ClassLoaderUtil#getClassLoader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourcesUtils.java From simple-robot-core with Apache License 2.0 | 6 votes |
/** * 从properties中读取对应的active内容,追加到指定的properties中 * 覆盖追加 * @param baseResourceName 主配置资源文件 * @param properties 此配置文件的properties信息 */ public static void resourceActive(String baseResourceName, String[] actives, Properties properties, ClassLoader loader){ if(loader == null){ loader = ClassLoaderUtil.getClassLoader(); } final int lastIndexOf = baseResourceName.lastIndexOf("."); String[] activeResourceNames; if(lastIndexOf > 0){ final String prefix = baseResourceName.substring(0, lastIndexOf); final String suffix = baseResourceName.substring(lastIndexOf); activeResourceNames = Arrays.stream(actives).map(ac -> prefix + "-" + ac + suffix).toArray(String[]::new); }else{ activeResourceNames = Arrays.stream(actives).map(ac -> baseResourceName + "-" + ac).toArray(String[]::new); } for (String activeResourceName : activeResourceNames) { final Resource resource = ResourcesUtils.getResource(activeResourceName, loader); try { final InputStream resourceStream = resource.getStream(); properties.load(resourceStream); }catch (NoResourceException | IOException e){ throw new ConfigurationException("can not load active config \"" + activeResourceName + "\": " + e.getLocalizedMessage(), e); } } }
Example 2
Source File: ResourcesUtils.java From simple-robot-core with Apache License 2.0 | 5 votes |
/** * 获取资源列表 * @param path path资源路径 * @param loader 类加载器,如果为null则获取当前线程的类加载器 */ public static List<URL> getResources(String path, ClassLoader loader){ final Enumeration<URL> resources; if(loader == null){ loader = ClassLoaderUtil.getClassLoader(); } try { resources = loader.getResources(path); } catch (IOException e) { throw new IORuntimeException(e); } return CollUtil.newArrayList(resources); }
Example 3
Source File: PluginFactory.java From Jpom with MIT License | 4 votes |
private static void addPlugin(String pluginName, File file) { DefaultSystemLog.getLog().info("加载:{}插件", pluginName); ClassLoader contextClassLoader = ClassLoaderUtil.getClassLoader(); JarClassLoader.loadJar((URLClassLoader) contextClassLoader, file); }