String (String jarPath, final Pattern jarPattern, String manifestPath, String versionGroupName) { try { File[] jars = LibrariesUtil.getFilesInDirectoryByPattern(jarPath, jarPattern); if (jars.length == 0) { return null; } if (jars.length > 1) { Arrays.sort(jars); } try (JarFile jarFile = new JarFile(jars[0])) { JarEntry jarEntry = jarFile.getJarEntry(manifestPath); if (jarEntry == null) { return null; } Manifest manifest; try (InputStream inputStream = jarFile.getInputStream(jarEntry)) { manifest = new Manifest(inputStream); } final String version = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION); if (version != null) { return version; } final Matcher matcher = jarPattern.matcher(jars[0].getName()); if (matcher.matches()) { try { return matcher.group(versionGroupName); } catch (IllegalArgumentException e) { LOG.error(e); } } return null; } } catch (Exception e) { LOG.debug(e); return null; } }