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

了解 JAVA classloader

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
nd object
    // code (.class)
    String javaFilename = fileStub+".java";
    String classFilename = fileStub+".class";
    File javaFile = new File( javaFilename );
    File classFile = new File( classFilename );
    //System.out.println( "j "+javaFile.lastModified()+" c "+
    //  classFile.lastModified() );
    // First, see if we want to try compiling.  We do if (a) there
    // is source code, and either (b0) there is no object code,
    // or (b1) there is object code, but it''s older than the source
    if (javaFile.exists() &&
         (!classFile.exists() ||
          javaFile.lastModified() > classFile.lastModified())) {
      try {
        // Try to compile it.  If this doesn''t work, then
        // we must declare failure.  (It''s not good enough to use
        // and already-existing, but out-of-date, classfile)
        if (!compile( javaFilename ) || !classFile.exists()) {
          throw new ClassNotFoundException( "Compile failed: "+javaFilename );
        }
      } catch( IOException ie ) {
        // Another place where we might come to if we fail
        // to compile
        throw new ClassNotFoundException( ie.toString() );
      }
    }
    // Let''s try to load up the raw bytes, assuming they were
    // properly compiled, or didn''t need to be compiled
    try {
      // read the bytes
      byte raw = getBytes( classFilename );
      // try to turn them into a class
      clas = defineClass( name, raw, 0, raw.length );
    } catch( IOException ie ) {
      // This is not a failure!  If we reach here, it might
      // mean that we are dealing with a class in a library,
      // such as java.lang.Object
    }
    //System.out.println( "defineClass: "+clas );
    // Maybe the class is in a library -- try loading
 &n

网学推荐

免费论文

原创论文

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