Skip to content

Commit

Permalink
Load uberjar in system clasloader instead of making new one
Browse files Browse the repository at this point in the history
  • Loading branch information
micha committed Oct 27, 2015
1 parent 61c948f commit 383d282
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions boot/loader/src/boot/Loader.java
Expand Up @@ -199,6 +199,16 @@ public class Loader {
latestBinaryFile() throws Exception {
return binaryFile(latestInstalledVersion(bindir().listFiles())); }

public static URLClassLoader
loadJar(File jar) throws Exception {
URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sc = URLClassLoader.class;
Method cm = sc.getDeclaredMethod("addURL", URL.class);

cm.setAccessible(true);
cm.invoke(cl, new Object[]{jar.toURI().toURL()});
return cl; }

public static void
main(String[] args) throws Exception {
String[] a = args;
Expand All @@ -217,10 +227,8 @@ public class Loader {
System.setProperty("BOOT_VERSION", initialVersion);
System.err.println("Running for the first time: updating to latest version."); }

URL url = f.toURI().toURL();
ClassLoader cl = new URLClassLoader(new URL[]{url});
Class c = Class.forName("boot.App", true, cl);
Method m = c.getMethod("main", String[].class);
URLClassLoader cl = loadJar(f);
Class c = Class.forName("boot.App", true, cl);
Method m = c.getMethod("main", String[].class);

tccl(cl);
m.invoke(null, new Object[]{a}); }}

0 comments on commit 383d282

Please sign in to comment.