blob: b63e5e6ec4a79968352084a6a862904d2d5bcf84 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
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;
}
}
|