解决加载相同的类

  URLClassLoader classLoader1 = new URLClassLoader(new URL[]{new URL("file:///F:/test_clazz1/test.jar")});
  Class clazz1 = classLoader1.loadClass("Test");
  URLClassLoader classLoader2 = new URLClassLoader(new URL[]{new URL("file:///F:/test_clazz2/test.jar")});
  Class clazz2 = classLoader2.loadClass("Test");
  Object object1 = clazz1.newInstance();
  Object object2 = clazz2.newInstance();
  clazz1.getMethod("say").invoke(object1);
  clazz2.getMethod("say").invoke(object2);

你可能感兴趣的:(加载)