Created
December 15, 2014 15:02
-
-
Save kidinov/bc850f05847b7202b87f to your computer and use it in GitHub Desktop.
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
public static Observer loadObserver(String path, ISender server, int id) { | |
File file = new File(path); | |
try { | |
URL url = file.getParentFile().toURI().toURL(); | |
URL[] urls = new URL[]{url}; | |
// Create a new class loader with the directory | |
ClassLoader cl = new URLClassLoader(urls); | |
// Load in the class; MyClass.class should be located in | |
Class cls = cl.loadClass(file.getName().replaceFirst("[.][^.]+$", "")); | |
return (Observer) cls.getDeclaredConstructor(ISender.class, int.class).newInstance(server, id); | |
} catch (Exception e) { | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment