diff options
author | Jonathan Bauer | 2014-09-18 17:44:12 +0200 |
---|---|---|
committer | Jonathan Bauer | 2014-09-18 17:44:12 +0200 |
commit | ef9b3190fc4c1af2d132fe7cc2ce61269605bcd6 (patch) | |
tree | 770af37999a25bd4a3747964e8a4a7fcaec3cc5c /dozentenmodul/src/main/java | |
parent | [client] only enable upload button if selected file is a vmdk (diff) | |
download | tutor-module-ef9b3190fc4c1af2d132fe7cc2ce61269605bcd6.tar.gz tutor-module-ef9b3190fc4c1af2d132fe7cc2ce61269605bcd6.tar.xz tutor-module-ef9b3190fc4c1af2d132fe7cc2ce61269605bcd6.zip |
[client] fix version detection for all jres
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r-- | dozentenmodul/src/main/java/models/Version.java | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/dozentenmodul/src/main/java/models/Version.java b/dozentenmodul/src/main/java/models/Version.java index a5eafe6d..b63e5e6e 100644 --- a/dozentenmodul/src/main/java/models/Version.java +++ b/dozentenmodul/src/main/java/models/Version.java @@ -1,7 +1,11 @@ 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 { @@ -11,15 +15,28 @@ public class Version { // Maven writes a version number derived from the current timestamp // to MANIFEST.MF - read it if (version == null) { + JarFile jf = null; try { - InputStream is = Version.class - .getResourceAsStream("/META-INF/MANIFEST.MF"); + 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; |