cn.hutool.core.util.ClassLoaderUtil Java Examples

The following examples show how to use cn.hutool.core.util.ClassLoaderUtil. 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: PayAutoConfig.java    From yue-library with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public Pay pay() {
	// 微信
	if (wxPayProperties.isEnabled()) {
		if (!ClassLoaderUtil.isPresent("com.egzosn.pay.wx.api.WxPayService")) {
			log.error("【支付配置】未引入依赖模块:pay-java-wx");
		}
		wxPay();
	}
	
	// 支付宝
	if (aliPayProperties.isEnabled()) {
		if (!ClassLoaderUtil.isPresent("com.egzosn.pay.ali.api.AliPayService")) {
			log.error("【支付配置】未引入依赖模块:pay-java-ali");
		}
		aliPay();
	}
	
	// Bean
       return new Pay(payServiceMap);
   }
 
Example #2
Source File: ResourcesUtils.java    From simple-robot-core with Apache License 2.0 6 votes vote down vote up
/**
 * 从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 #3
Source File: BeanConverter.java    From WeBASE-Collect-Bee with Apache License 2.0 5 votes vote down vote up
public IdEntity convertBOToEntity(CommonBO bo, String type)
        throws InstantiationException, IllegalAccessException, UtilException {
    IdEntity entity = (IdEntity) ClassLoaderUtil
            .loadClass("com.webank.webasebee.db.generated.entity." + type + "." + bo.getIdentifier()).newInstance();
    BeanUtil.copyProperties(bo, entity);
    return entity;
}
 
Example #4
Source File: ResourcesUtils.java    From simple-robot-core with Apache License 2.0 5 votes vote down vote up
/**
 * 获取资源列表
 * @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 #5
Source File: PluginFactory.java    From Jpom with MIT License 4 votes vote down vote up
private static void addPlugin(String pluginName, File file) {
    DefaultSystemLog.getLog().info("加载:{}插件", pluginName);
    ClassLoader contextClassLoader = ClassLoaderUtil.getClassLoader();
    JarClassLoader.loadJar((URLClassLoader) contextClassLoader, file);
}