Improved code that gets the Helma home directory from the launcher.jar URL.

This commit is contained in:
hns 2003-07-09 15:23:30 +00:00
parent b8dea83bce
commit 2790dde1b4

View file

@ -27,7 +27,7 @@ import java.util.ArrayList;
/** /**
* Helma bootstrap class. Figures out Helma home directory, sets up class path and * Helma bootstrap class. Figures out Helma home directory, sets up class path and
* lauchnes main class. * lauchnes main class. This class must be invoked from a jar file in order to work.
*/ */
public class Main { public class Main {
public static final String[] jars = { public static final String[] jars = {
@ -69,21 +69,28 @@ public class Main {
// jar:<url>!/{entry} // jar:<url>!/{entry}
// we strip away the jar: prefix and the !/{entry} suffix // we strip away the jar: prefix and the !/{entry} suffix
// to get the original jar file URL // to get the original jar file URL
installDir = launcherUrl.toString().substring(4);
int excl = installDir.indexOf("!"); String jarUrl = launcherUrl.toString();
if (excl > -1) { if (!jarUrl.startsWith("jar:") || jarUrl.indexOf("!") < 0) {
installDir = installDir.substring(0, excl); throw new RuntimeException(" Unable to get JAR URL from "+jarUrl);
launcherUrl = new URL(installDir); }
jarUrl = jarUrl.substring(4);
int excl = jarUrl.indexOf("!");
jarUrl = jarUrl.substring(0, excl);
launcherUrl = new URL(jarUrl);
File f = new File(launcherUrl.getPath()); File f = new File(launcherUrl.getPath());
installDir = f.getParentFile().getCanonicalPath(); installDir = f.getParentFile().getCanonicalPath();
}
} catch (Exception x) { } catch (Exception x) {
// unable to get Helma installation dir from launcher jar // unable to get Helma installation dir from launcher jar
System.err.println("Unable to get Helma installation directory: " + x); System.err.println("Unable to get Helma installation directory: ");
System.err.println(x.getMessage());
System.exit(2); System.exit(2);
} }
} }