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

后端 未结 7 1401
后悔当初
后悔当初 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:10

        try {
            final JarFile jarFile = (JarFile) this.getClass().getProtectionDomain().getCodeSource().getLocation().getContent();
            final Manifest manifest = jarFile.getManifest();
            final Map manifestProps = manifest.getMainAttributes().entrySet().stream()
                    .collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue()));
        ...
        } catch (final IOException e) {
            LOG.error("Unable to read MANIFEST.MF", e);
            ...
        }
    

    This will work only if you launch your app via java -jar command, it won't work if one create an integration test.

提交回复
热议问题