package models; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Properties; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class Version { private static String version = null; public static String getVersion() { // Maven writes a version number derived from the current timestamp // to MANIFEST.MF - read it if (version == null) { JarFile jf = null; try { String classPath = Version.class.getName().replace('.', '/') + ".class"; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); URL classPathUrl = classLoader.getResource(classPath); String jarPath = classPathUrl.getPath().replaceAll("![^!]*$", "").replaceAll("^(file:|jar:)*", ""); jf = new JarFile(jarPath); JarEntry je = jf.getJarEntry("META-INF/MANIFEST.MF"); InputStream is = jf.getInputStream(je); Properties p = new Properties(); p.load(is); version = p.getProperty("Version-Timestamp"); } catch (Exception e) { e.printStackTrace(); version = "unknown"; } finally { if (jf != null) try { jf.close(); } catch (IOException e) { } } } return version; } }