cn.hutool.core.util.ClassUtil Java Examples

The following examples show how to use cn.hutool.core.util.ClassUtil. 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: DuangClassLoader.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private void init() {
    String packagePath = SettingUtil.getString("package.name");
    if(!RobotUtil.isDevMode() && ToolsKit.isEmpty(packagePath)) {
        logger.info("热部署功能只允许在开发环境下运行");
        return;
    }
    CLASSLOADER_SET = new HashSet<>();
    String classFileDir = ClassUtil.getClassPath();
    BASE_PACKAGE_PATH = classFileDir;
    Set<Class<?>> classSet = ClassUtil.scanPackage(packagePath);
    if (ToolsKit.isNotEmpty(classSet)) {
        for (Class<?> clazz : classSet) {
            if(!ClassUtil.isNormalClass(clazz)) {
                continue;
            }
            String fileName = clazz.getName().replace('.', '/').concat(".class");
            File file = new File(classFileDir + fileName);
            if (file.isFile()) {
                getClassData(file);
            }
            CLASSLOADER_SET.add(clazz.getName());
        }
    }

}
 
Example #2
Source File: OpenAgvConfigure.java    From openAGV with Apache License 2.0 6 votes vote down vote up
private void init() {
        String configDir = "config"; // 只能是以config作为文件夹
        URL url = ClassUtil.getResourceURL(configDir);
        String classesPath = url.getPath();
        File dir = new File(classesPath);
        classesPath = dir.getParentFile().getAbsolutePath();
        logger.info("OpenTcsConfigure Path: {}", classesPath);
//        System.setProperty("java.util.logging.config.file", classesPath+File.separator+subDir+File.separator+"logging.config");
        System.setProperty("java.security.policy", classesPath + File.separator + configDir + File.separator + "java.policy");
        System.setProperty("opentcs.base", classesPath);
        System.setProperty("opentcs.home", ".");
        System.setProperty("splash", classesPath + File.separator + "bin" + File.separator + "splash-image.gif");
        System.setProperty("file.encoding", CharsetUtil.UTF_8.name());
        // 设置DLL文件根路径
        System.setProperty("jna.library.path", classesPath + File.separator +"dll");
        PropertyConfigurator.configure(classesPath + File.separator + "log4j.properties");
        logger.warn("OpenAgvConfigure init success");

    }
 
Example #3
Source File: CheckPath.java    From Jpom with MIT License 6 votes vote down vote up
@PreLoadMethod(1)
private static void checkToolsJar() {
    try {
        for (String item : CLASS_NAME) {
            ClassUtil.loadClass(item, false);
        }
    } catch (Exception e) {
        File file = StringUtil.getToolsJar();
        if (file.exists() && file.isFile()) {
            DefaultSystemLog.getLog().error("Jpom未能正常加载tools.jar,请检查当前系统环境变量是否配置:JAVA_HOME,或者检查Jpom管理命令是否正确", e);
        } else {
            DefaultSystemLog.getLog().error("当前JDK中没有找到tools.jar,请检查当前JDK是否安装完整,文件完整路径是:" + file.getAbsolutePath(), e);
        }
        System.exit(-1);
    }
}
 
Example #4
Source File: IocHelper.java    From openAGV with Apache License 2.0 5 votes vote down vote up
public void ioc(Object serviceObj, Class clazz) throws Exception {
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        boolean isInjectAnn = field.isAnnotationPresent(Import.class) ||
                field.isAnnotationPresent(Inject.class) ||
                field.isAnnotationPresent(javax.inject.Inject.class);
        if (isInjectAnn) {
            Class<?> fieldTypeClass = field.getType();
            if (fieldTypeClass.equals(clazz)) {
                throw new RobotException(clazz.getSimpleName() + " can't not already import " + fieldTypeClass.getSimpleName());
            }
            if (!MongoDao.class.equals(field.getType()) &&
                    (fieldTypeClass.isAnnotationPresent(Controller.class) || fieldTypeClass.isAnnotationPresent(Service.class)) ) {
                Object iocServiceObj = Optional.ofNullable(BeanHelper.duang().getBean(fieldTypeClass)).orElseThrow(NullPointerException::new);
                field.setAccessible(true);
                field.set(serviceObj, iocServiceObj);
            } else if (MongoDao.class.equals(field.getType())) {
                ParameterizedType paramType = (ParameterizedType) field.getGenericType();
                Type[] types = paramType.getActualTypeArguments();
                if (ToolsKit.isNotEmpty(types)) {
                    // <>里的泛型类
                    Class<?> paramTypeClass = ClassUtil.loadClass(types[0].getTypeName());
                    Object daoObj = getDbInjectDao(field, paramTypeClass);
                    if (null != daoObj) {
                        field.setAccessible(true);
                        field.set(serviceObj, daoObj);
                    }
                }
            }
        }
    }
}
 
Example #5
Source File: Test.java    From Jpom with MIT License 5 votes vote down vote up
public static void main(String[] args) {

        System.out.println(FileUtil.normalize("sss/ss/../ssss"));
        System.out.println(FileUtil.normalize("./ssss/ssss"));
        CacheControllerFeature.init();
        Map<ClassFeature, Set<MethodFeature>> classFeatureSetMap = CacheControllerFeature.getFeatureMap();
        ClassFeature monitor = ClassFeature.valueOf("MONITOR");
        System.out.println(monitor.getName());
        System.out.println(classFeatureSetMap);

        Class<?> typeArgument = ClassUtil.getTypeArgument(RoleService.class);
        System.out.println(typeArgument);
    }
 
Example #6
Source File: Application.java    From openAGV with Apache License 2.0 4 votes vote down vote up
public Application hotSwap() {
    this.hotSwapDir = ClassUtil.getClassPath();
    return this;
}
 
Example #7
Source File: BaseOperService.java    From Jpom with MIT License 4 votes vote down vote up
public BaseOperService(String fileName) {
    this.fileName = fileName;
    this.typeArgument = ClassUtil.getTypeArgument(this.getClass());
}