当前位置: 网学 > 编程文档 > JAVA > 正文

了解 JAVA classloader

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
bsp;  // the normal way
    if (clas==null) {
      clas = findSystemClass( name );
    }
    //System.out.println( "findSystemClass: "+clas );
    // Resolve the class, if any, but only if the "resolve"
    // flag is set to true
    if (resolve && clas != null)
      resolveClass( clas );
    // If we still don''t have a class, it''s an error
    if (clas == null)
      throw new ClassNotFoundException( name );
    // Otherwise, return the class
    return clas;
  }
}

CCRun.java
以下是 CCRun.java 的源代码

// $Id$
import java.lang.reflect.*;
/*
CCLRun executes a Java program by loading it through a
CompilingClassLoader.
*/
public class CCLRun
{
  static public void main( String args ) throws Exception {
    // The first argument is the Java program (class) the user
    // wants to run
    String progClass = args[0];
    // And the arguments to that program are just
    // arguments 1..n, so separate those out into
    // their own array
    String progArgs = new String[args.length-1];
    System.arraycopy( args, 1, progArgs, 0, progArgs.length );
    // Create a CompilingClassLoader
    CompilingClassLoader ccl = new CompilingClassLoader();
    // Load the main class through our CCL
    Class clas = ccl.loadClass( progClass );
    // Use reflection to call its main() method, and to
    // pass the arguments in.
    // Get a class representing the type of the main method''s argument
    Class mainArgType = { (new String[0]).getClass() };
    // Find the standard main method in the class
    Method main = clas.getMethod( "main", mainArgType );
    // Create a list containing the arguments -- in this case,
    // an array of strings
    Object argsArray = { progArgs };
    // Call the method
    main.invoke( null, argsArray );
  }
}

Foo.java
以下是 Foo.java 的源代码

// $Id$
public class Foo
{
  static public void main( String args ) throws Exception {
    System.out.println( "foo! "+args[0]+" "+args );
    new Bar( args[0], args );
  }
}

Bar.java
以下是 Bar.java 的源代码

// $Id$
import baz.*;
public class Bar
{
  public Bar( String a, String b ) {
    System.out.println( "bar! "+a+

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号