java获取classpath

public class PathTest {
    public static void main(String[] args) {
        //获取根路径三种方式
        System.out.println(PathTest.class.getClassLoader().getResource(""));
        System.out.println(ClassLoader.getSystemClassLoader().getResource(""));
        System.out.println(Thread.currentThread().getContextClassLoader().getResource(""));
        //获取当前类所在路径
        System.out.println(PathTest.class.getResource(""));
    }
}

 

你可能感兴趣的:(java获取classpath)