diff options
author | Tobias Kellner <tobias.kellner@iaik.tugraz.at> | 2015-01-12 18:59:30 +0100 |
---|---|---|
committer | Tobias Kellner <tobias.kellner@iaik.tugraz.at> | 2015-02-04 03:49:11 +0100 |
commit | 27ed0a72faaa85ba456a24c8292735bbe2fa82ab (patch) | |
tree | 0368d8206375b8eea3a2f6ed21aeb9ce8f98b7fb /BKUWebStart/src/main/java | |
parent | dd2338aac4651c1bfea45c6b725d923fda903d04 (diff) | |
download | mocca-27ed0a72faaa85ba456a24c8292735bbe2fa82ab.tar.gz mocca-27ed0a72faaa85ba456a24c8292735bbe2fa82ab.tar.bz2 mocca-27ed0a72faaa85ba456a24c8292735bbe2fa82ab.zip |
JarLocation fix
Diffstat (limited to 'BKUWebStart/src/main/java')
-rw-r--r-- | BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java index 287e3b9d..30a6ce3d 100644 --- a/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java +++ b/BKUWebStart/src/main/java/at/gv/egiz/bku/webstart/Launcher.java @@ -29,23 +29,30 @@ import at.gv.egiz.bku.webstart.gui.StatusNotifier; import at.gv.egiz.bku.webstart.gui.BKUControllerInterface; import at.gv.egiz.bku.webstart.gui.MOCCAIcon; import iaik.asn1.CodingException; + import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.Locale; import javax.jnlp.UnavailableServiceException; + //import com.sun.javaws.security.JavaWebStartSecurity; import java.awt.Desktop; import java.awt.SplashScreen; import java.net.BindException; import java.net.MalformedURLException; import java.net.URL; +import java.net.URLDecoder; +import java.security.CodeSource; import java.security.GeneralSecurityException; import java.util.jar.Attributes; import java.util.jar.Manifest; + import javax.jnlp.BasicService; import javax.jnlp.ServiceManager; + import org.mortbay.util.MultiException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,7 +113,7 @@ public class Launcher implements BKUControllerInterface { static { String tmp = Configurator.UNKOWN_VERSION; try { - String bkuWebStartJar = Launcher.class.getProtectionDomain().getCodeSource().getLocation().toString(); + String bkuWebStartJar = getJarLocation(Launcher.class); URL manifestURL = new URL("jar:" + bkuWebStartJar + "!/META-INF/MANIFEST.MF"); if (log.isTraceEnabled()) { log.trace("read version information from " + manifestURL); @@ -118,6 +125,8 @@ public class Launcher implements BKUControllerInterface { } } catch (IOException ex) { log.error("failed to read version", ex); + } catch (URISyntaxException ex) { + log.error("failed to read version", ex); } finally { version = tmp; log.info("BKU Web Start " + version); @@ -188,6 +197,24 @@ public class Launcher implements BKUControllerInterface { throw new IOException("current platform does not support Java Desktop API"); } + private static String getJarLocation(Class<?> c) throws URISyntaxException, + UnsupportedEncodingException { + CodeSource codeSource = c.getProtectionDomain().getCodeSource(); + + String loc; + + if (codeSource.getLocation() != null) { + loc = codeSource.getLocation().toString(); + } else { + loc = c.getResource(c.getSimpleName() + ".class").toString(); + } + if (loc.startsWith("jar:")) { + loc = loc.substring(loc.indexOf(":") + 1, loc.indexOf("!")); + loc = URLDecoder.decode(loc, "UTF-8"); + } + return loc; + } + private void initStart() { try { status.info(StatusNotifier.MESSAGE_START); |