java中jar包内的类访问jar包内部的资源文件的路径问题

时间:2022-09-17 09:07:18

采用如下方法:

    public void test(){  
        String class_str = this.getClass().getResource("/logback.xml").getPath();  
        String class_str2 = TempTest.class.getResource("/logback.xml").getPath();  
        String classLoader_str = this.getClass().getClassLoader().getResource("logback.xml").getPath();  
        InputStream is = this.getClass().getClassLoader().getResourceAsStream("logback.xml");  
        System.out.println(class_str);  
        System.out.println(class_str2);  
        System.out.println(classLoader_str);  
        System.out.println(is == null );  
    }