private String getVersion ( final Class launcherClass , final String groupId , final String artifactId ) throws NotAvailableException { String version = null ; // try to load from maven properties first try { Properties p = new Properties ( ) ; InputStream is = getClass ( ) . getResourceAsStream ( "/META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties" ) ; if ( is != null ) { p . load ( is ) ; version = p . getProperty ( "version" , "" ) ; } } catch ( Exception e ) { // ignore } // fallback to using Java API if ( version == null ) { Package launcherPackage = launcherClass . getClass ( ) . getPackage ( ) ; if ( launcherPackage != null ) { version = launcherPackage . getImplementationVersion ( ) ; if ( version == null ) { version = launcherPackage . getSpecificationVersion ( ) ; } } } if ( version == null ) { // we could not compute the version so a blank throw new NotAvailableException ( "Application Version" ) ; } return version ; }
Method tries to detect the application Version .