Getting application version from pom

后端 未结 4 1899
天涯浪人
天涯浪人 2020-12-29 11:30

I have a rest endpoint used to return information about application (so far only app version) But so far this info is hardcoded, and it\'s pretty easy to forget to change it

4条回答
  •  鱼传尺愫
    2020-12-29 11:58

    You better use build-in manifest.

    new Manifest(Application.class.getResourceAsStream("/META-INF/manifest.mf"))
    

    For the concrete impl-version:

    new Manifest(Application.class.getResourceAsStream("/META-INF/manifest.mf"))
                .getMainAttributes()
                .get(Attributes.Name.IMPLEMENTATION_VERSION)
    

    Using maven do not forget to create the manifest using:

    
    
        
            
                
                    org.apache.maven.plugins
                    maven-jar-plugin
                    2.4
                    
                        
                            
                                true
                            
                        
                    
                
            
        
    
    

提交回复
热议问题