-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from imario42/master
alternative classloader strategy
- Loading branch information
Showing
2 changed files
with
85 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package fxlauncher; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by im on 22.02.17. | ||
*/ | ||
public class FxlauncherClassCloader extends URLClassLoader | ||
{ | ||
public FxlauncherClassCloader(ClassLoader parentClassLoader) | ||
{ | ||
super(buildClasspath(System.getProperty("java.class.path")), parentClassLoader); | ||
} | ||
|
||
void addUrls(List<URL> urls) | ||
{ | ||
for (URL url : urls) | ||
{ | ||
this.addURL(url); | ||
} | ||
} | ||
|
||
private static URL[] buildClasspath(String classPath) | ||
{ | ||
if (classPath == null || classPath.trim().length() < 1) | ||
{ | ||
return new URL[0]; | ||
} | ||
|
||
List<URL> urls = new ArrayList<>(); | ||
|
||
int pos; | ||
while ((pos = classPath.indexOf(File.pathSeparatorChar)) > -1) | ||
{ | ||
String part = classPath.substring(0, pos); | ||
|
||
addClasspathPart(urls, part); | ||
|
||
classPath = classPath.substring(pos + 1); | ||
} | ||
|
||
addClasspathPart(urls, classPath); | ||
|
||
return urls.toArray(new URL[urls.size()]); | ||
} | ||
|
||
private static void addClasspathPart(List<URL> urls, String part) | ||
{ | ||
if (part == null || part.trim().length() < 1) | ||
{ | ||
return; | ||
} | ||
|
||
try | ||
{ | ||
urls.add(new File(part).toURI().toURL()); | ||
} | ||
catch (MalformedURLException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters