How to read my META-INF/MANIFEST.MF file in a Spring Boot app?

后端 未结 7 1425
后悔当初
后悔当初 2020-12-30 02:31

I\'m trying to read my META-INF/MANIFEST.MF file from my Spring Boot web app (contained in a jar file).

I\'m trying the following code:

        Input         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-30 03:18

    public Properties readManifest() throws IOException {
        Object inputStream = this.getClass().getProtectionDomain().getCodeSource().getLocation().getContent();
        JarInputStream jarInputStream = new JarInputStream((InputStream) inputStream);
        Manifest manifest = jarInputStream.getManifest();
        Attributes attributes = manifest.getMainAttributes();
        Properties properties = new Properties();
        properties.putAll(attributes);
        return properties;
    }
    

提交回复
热议问题