读取jar同级目录下的yml文件,若依框架没有实现的部分。

                System.out.println("------ztj----jarPath1---"+Utils.class.getProtectionDomain().getCodeSource().getLocation().getPath());
                String jarPath = new File(Utils.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent();
                System.out.println("------ztj----jarPath2---"+jarPath);
                String configPath = new File(jarPath).getParent();
                System.out.println("------ztj----jarPath3---"+new File(configPath).getParent()+"/application.yml");
                URI uri = new URI(new File(configPath).getParent()+"/application.yml");
                File file=new File(uri.getPath());
                System.out.println(file.getAbsolutePath());
                InputStream as = new FileInputStream(file);
                if(as!=null){
                    m_root = (Map) m_yaml.load(as);
                    System.out.println("------ztj----4---");
                }
                System.out.println("------ztj----b--");

1) 先读取绝对路径;
2)将file:路径转化File能读取的数据;
3)后面就诺依框架自带的。
多次用chart-GPT都是不对的在百度上搜也不管用,不断调试打印,弄正确打印出来了,如果遇同样问题的人,少走弯路。在服务器调试jar有什么好的工具呢,总打印打包上传这个效率太低了,有推荐的吗?

打印的结果:
------ztj----jarPath1---file:/data/www/fisher_netty/fisher-netty.jar!/BOOT-INF/classes!/
------ztj----jarPath2---file:/data/www/fisher_netty/fisher-netty.jar!/BOOT-INF
------ztj----jarPath3---file:/data/www/fisher_netty/application.yml
/data/www/fisher_netty/application.yml
 

Logo

快速构建 Web 应用程序

更多推荐