How to get package version at running Tomcat?

后端 未结 2 1343
南笙
南笙 2021-01-05 13:37

How to get package version at running Tomcat?

I try getClass().getPackage().getImplementationVersion() but this always returns null. I guess it is becau

2条回答
  •  有刺的猬
    2021-01-05 14:20

    Solved by
    1) Creating META-INF\MANIFEST.MF in webapp folder with mvn war:manifest
    2) Coding

    version  = getClass().getPackage().getImplementationVersion();  
    if (version==null) {
        Properties prop = new Properties();
        try {
            prop.load(getServletContext().getResourceAsStream("/META-INF/MANIFEST.MF"));
            version = prop.getProperty("Implementation-Version");
        } catch (IOException e) {
            logger.error(e.toString());
        }
    }
    logger.info("Starting App version "+version);
    

    Thanks to @javadude answer at How do I read the manifest file for a webapp running in apache tomcat?

提交回复
热议问题