SpringBoot获取项目名称

    public void readJarFile() throws IOException {
        String jarFilePath = getJarFilePath();
        JarFile jarFile = new JarFile(new File(jarFilePath));
        Enumeration entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry jarEntry = entries.nextElement();
            String innerPath = jarEntry.getName();
            if (innerPath.endsWith("MANIFEST.MF")) {
                InputStream inputStream = jarFile.getInputStream(jarEntry);
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                String line = null;
                while (null != (line = bufferedReader.readLine())) {
                    //这里处理mf文件,读取项目名称和版本
                }
                bufferedReader.close();
            }
        }
        jarFile.close();
    }

    public String getJarFilePath() throws FileNotFoundException {
        ApplicationHome h = new ApplicationHome(getClass());
        File jarFile = h.getSource();
        return jarFile.getAbsolutePath();
    }

你可能感兴趣的:(Spring)