Skip to content

Instantly share code, notes, and snippets.

@kidinov
Created December 15, 2014 15:02
Show Gist options
  • Save kidinov/bc850f05847b7202b87f to your computer and use it in GitHub Desktop.
Save kidinov/bc850f05847b7202b87f to your computer and use it in GitHub Desktop.
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