Reflections的使用

Reflections常常用来扫描工程中的Jar包或class文件,这是用来累记常用的一些技巧类用法的文章

排除

1、只允许扫描class文件

ConfigurationBuilder config = new ConfigurationBuilder();
config.addUrls(ClasspathHelper.forPackage(packageName));
config.filterInputsBy(new FilterBuilder()
                .exclude("^(?!org\\.nd4j\\.linalg\\.api\\.ops).*")    //排除某个包
                .exclude("^(?!.*\\.class$).*$")); //只允许扫描class
                //排除一些常用的,不需要的包
                .exclude("^org.nd4j.*").exclude("^org.bytedeco.*") //JavaCPP
                .exclude("^com.fasterxml.*")  //Jackson
                .exclude("^org.apache.*")     //Apache commons, Spark, log4j etc
                .exclude("^org.projectlombok.*").exclude("^com.twelvemonkeys.*")
                .exclude("^org.joda.*").exclude("^org.slf4j.*").exclude("^com.google.*")
                .exclude("^org.reflections.*").exclude("^ch.qos.*")     //Logback
config.setScanners(new TypeAnnotationsScanner(),new SubTypesScanner());
Reflections reflections = new Reflections(config);