编译后InterfaceA和ClassB的class文件都放到test.jar中了。

解决方案 »

  1.   

    可能是需要 iA = (InterfaceA)(loader.loadClass("ClassB").newInstance()); 不太确定,可以试试
      

  2.   

    生成URLClassLoader时用 URLClassLoader loader = new URLClassLoader(urls);就可以了,不要把第二个参数设为null,具体为什么还要等高手来解释
      

  3.   

    看jdk的源代码:
    /**
         * Constructs a new URLClassLoader for the given URLs. The URLs will be
         * searched in the order specified for classes and resources after first
         * searching in the specified parent class loader. Any URL that ends with
         * a '/' is assumed to refer to a directory. Otherwise, the URL is assumed
         * to refer to a JAR file which will be downloaded and opened as needed.
         *
         * <p>If there is a security manager, this method first
         * calls the security manager's <code>checkCreateClassLoader</code> method
         * to ensure creation of a class loader is allowed.
         * 
         * @param urls the URLs from which to load classes and resources
         * @param parent the parent class loader for delegation
         * @exception  SecurityException  if a security manager exists and its  
         *             <code>checkCreateClassLoader</code> method doesn't allow 
         *             creation of a class loader.
         * @see SecurityManager#checkCreateClassLoader
         */
        public URLClassLoader(URL[] urls, ClassLoader parent) {
    super(parent);
    // this is to make the stack depth consistent with 1.1
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkCreateClassLoader();
    }
    ucp = new URLClassPath(urls);
    acc = AccessController.getContext();
        }    /**
         * Constructs a new URLClassLoader for the specified URLs using the
         * default delegation parent <code>ClassLoader</code>. The URLs will
         * be searched in the order specified for classes and resources after
         * first searching in the parent class loader. Any URL that ends with
         * a '/' is assumed to refer to a directory. Otherwise, the URL is
         * assumed to refer to a JAR file which will be downloaded and opened
         * as needed.
         *
         * <p>If there is a security manager, this method first
         * calls the security manager's <code>checkCreateClassLoader</code> method
         * to ensure creation of a class loader is allowed.
         * 
         * @param urls the URLs from which to load classes and resources
         *
         * @exception  SecurityException  if a security manager exists and its  
         *             <code>checkCreateClassLoader</code> method doesn't allow 
         *             creation of a class loader.
         * @see SecurityManager#checkCreateClassLoader
         */
        public URLClassLoader(URL[] urls) {
    super();
    // this is to make the stack depth consistent with 1.1
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkCreateClassLoader();
    }
    ucp = new URLClassPath(urls);
    acc = AccessController.getContext();
        }
      

  4.   

    回复人: herbage_h2h() ( ) 信誉:100  2005-01-11 11:44:00  得分: 0  
     
     
       可能是需要 iA = (InterfaceA)(loader.loadClass("ClassB").newInstance()); 不太确定,可以试试  
     
    ----------------------------------------------------------------
    不是因为这个
      

  5.   

    回复人: herbage_h2h() ( ) 信誉:100  2005-01-11 12:29:00  得分: 0  
     
     
       生成URLClassLoader时用 URLClassLoader loader = new URLClassLoader(urls);就可以了,不要把第二个参数设为null,具体为什么还要等高手来解释  
     
    --------------------------------------------------------
    就是这个原因了