Java 获取运行时路径

Posted by zjh on November 22, 2021
 String path = PropertyUtil.class.getProtectionDomain()
                    .getCodeSource().getLocation().getPath();
            if(path.endsWith(".jar")){
                path = path.substring(0, path.lastIndexOf("/")+1);
            }
            System.out.println("\n\n===============================\n\n");
            System.out.printf("loading configFilePath address:「 %s%n", path +"generator-config.yml」");
            System.out.println("\n\n===============================\n\n");
            yamlPropertiesFactoryBean.setResources(new FileUrlResource(path+"generator-config.yml"));