Advertisement
Guest User

Untitled

a guest
May 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. package ru.edhunter;
  2. import java.io.File;
  3. import java.net.MalformedURLException;
  4. import java.net.URL;
  5. import java.net.URLClassLoader;
  6.  
  7. public class PluginManager {
  8. private final String pluginRootDirectory;
  9.  
  10. public PluginManager(String pluginRootDirectory) {
  11. this.pluginRootDirectory = pluginRootDirectory;
  12. }
  13.  
  14. public Plugin load(String pluginName, String pluginClassName)
  15. throws MalformedURLException, ClassNotFoundException,
  16. IllegalAccessException, InstantiationException {
  17.  
  18. File file = new File(pluginRootDirectory + "/" + pluginName + "/");
  19.  
  20. URL[] urls = new URL[]{file.toURI().toURL()};
  21.  
  22. URLClassLoader loader = new URLClassLoader(urls);
  23.  
  24. Plugin plugin = (Plugin)loader.loadClass(pluginClassName).newInstance();
  25.  
  26. return plugin;
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement