try new URL("file:/"+ jarfile );make sure your url is correct

解决方案 »

  1.   

    import java.net.*;
    public class ClassB {
      public ClassB() {
      }
      public static void main(String[] args)
      {
        try
        {
          URL[] url = new URL[] {new URL("file:" + ("c:\\1\\cls.jar")) };
          URLClassLoader loader = new URLClassLoader( url );
          System.out.println( System.getProperty("java.class.path"));
          Class cls = loader.loadClass("testclass.ClassA");
          System.out.println(cls.getName());
          ISome o = (ISome)cls.newInstance();
          o.print_hl();
        }
        catch( Exception ex )
        {
          ex.printStackTrace();
        }
      }
    }搞定