public static String getApplicationVersionFromJar ( Class < ? > _class , String _default ) { try { Enumeration < URL > resources = _class . getClassLoader ( ) . getResources ( "META-INF/MANIFEST.MF" ) ; while ( resources . hasMoreElements ( ) ) { Manifest manifest = new Manifest ( resources . nextElement ( ) . openStream ( ) ) ; Attributes attribs = manifest . getMainAttributes ( ) ; String ver = attribs . getValue ( Attributes . Name . IMPLEMENTATION_VERSION ) ; if ( ver == null ) { return _default ; } String rev = attribs . getValue ( "Implementation-Revision" ) ; if ( rev != null ) { ver += "-r" + rev ; } return ver ; } } catch ( IOException _ex ) { } return _default ; }
Read the JARs manifest and try to get the current program version from it .