package com.hhwy; import org.junit.Test; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import java.io.IOException; public class TestJunit { @Test public void test() throws IOException { ResourcePatternResolver rpr = new PathMatchingResourcePatternResolver(); //Resource[] resources = rpr.getResources("classpath*: **/*.class"); // classpath*:带*号会找jar中的class Resource[] resources = rpr.getResources("classpath: **/*.class"); // classpath*:不带*号只找自定义的类的class for (Resource res:resources){ String className = res.getURL().getPath(); className = className.split("(classes/)|(!/)")[1]; className = className.replace("/", ".").replace(".class", ""); System.err.println(className); } } }