You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ClassLoaderExecutor.java 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. package com.uqac.rthoni.java_rmi.server.executors;
  2. import com.uqac.rthoni.java_rmi.common.Command;
  3. import com.uqac.rthoni.java_rmi.server.ServerApplication;
  4. import java.io.File;
  5. import java.net.URL;
  6. import java.net.URLClassLoader;
  7. /**
  8. * Created by robin on 9/16/16.
  9. */
  10. public class ClassLoaderExecutor extends AbstractCommandExecutor {
  11. @Override
  12. public String getCommandName() {
  13. return "chargement";
  14. }
  15. @Override
  16. public String run(Command command, ServerApplication server) throws Exception {
  17. String className = command.getArgument(0, false);
  18. String classDir = command.getArgument(1, false);
  19. File root = new File(server.getClassDir(), classDir);
  20. URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
  21. server.addClassLoader(classLoader);
  22. // Class<?> cls = Class.forName(className, true, classLoader); // Should print "hello".
  23. // Object instance = cls.newInstance(); // Should print "world".
  24. // System.out.println(instance); // Should print "test.Test@hashcode".
  25. return null;
  26. }
  27. }