/** * Read the version information from a file with a given file name. The file must be a jar * manifest file and all its entries are searched for package names and their specification * version information. All information is collected in a map for later lookup of package names * and their versions. * * @param versionFileName name of the jar file containing version information */ public static String readVersionFromFile(String applicationName, String versionFileName) { try { FileInputStream fileInput = new FileInputStream(versionFileName); Manifest manifest = new Manifest(); manifest.read(fileInput); Map entries = manifest.getEntries(); // Now write out the pre-entry attributes Iterator entryIterator = entries.entrySet().iterator(); while (entryIterator.hasNext()) { Map.Entry currentEntry = (Map.Entry) entryIterator.next(); String packageName = currentEntry.getKey().toString(); packageName = normalizePackageName(packageName); Attributes attributes = (Attributes) currentEntry.getValue(); String packageSpecVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION); packageSpecVersion = extractVersionInfo(packageSpecVersion); return packageSpecVersion; } } catch (IOException exception) { exception.printStackTrace(); } // no version found return null; }