java.lang.Class

 

Java类库中的核心部分 String、Object、Class、Collection、ClassLoader、System、Runtime

java.lang.Class和ClassLoader

虚拟机为每种类型管理一个独一无二的Class对象。也就是说,每个类(型)都有一个Class对象。

String jarPath = System.getProperty("user.dir") + File.separator + "mainTask.jar";
File file = new File(jarPath);
URLClassLoader loader = null;
     if (file.exists()) {
          loader = new URLClassLoader(new URL[] { file.toURI().toURL() });
      }

JobDetail job = newJob(((org.quartz.Job) loader.loadClass(className).newInstance()).getClass())
.withIdentity(index.toString() + className, "group").build();

http://lavasoft.blog.51cto.com/62575/15433

java.lang.Runtime

 Runtime类封装了运行时的环境,java代码和环境互交的入口。

http://lavasoft.blog.51cto.com/62575/15565

java.lang.Process

 Process 类提供了执行从进程输入、执行输出到进程、等待进程完成、检查进程的退出状态以及销毁(杀掉)进程的方法

http://lavasoft.blog.51cto.com/62575/15599

class ExecDemo {
    public static void main(String args[]){
        Runtime r = Runtime.getRuntime();
        Process p = null;
        try{
//          p = r.exec("notepad");
            p = r.exec("ipconfig");//windows系统
            p.getInputStream();
//          BufferedWriter bw=new BufferedWriter(new OutputStreamWriter( p.getOutputStream()));
            BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line="";
            while((line=br.readLine())!=null){
                System.out.println(line);
            }
            br.close();
            p.waitFor();
        } catch (Exception e) {
            System.out.println("Error executing notepad.");
        }
        System.out.println("Notepad returned " + p.exitValue());
    }
}

ClassLoader

http://blog.csdn.net/xyang81/article/details/7292380

 

URLClassLoader是ClassLoader的子类,api文档介绍:

该类加载器用于从指向 JAR 文件和目录的 URL 的搜索路径加载类和资源。这里假定任何以 '/' 结束的 URL 都是指向目录的。如果不是以该字符结束,则认为该 URL 指向一个将根据需要打开的 JAR 文件。
创建 URLClassLoader 实例的 AccessControlContext 线程将在后续加载类和资源时使用。
为加载的类默认授予只能访问 URLClassLoader 创建时指定的 URL 的权限。

 

posted @ 2017-08-09 15:53  Nucky_yang  阅读(229)  评论(0编辑  收藏  举报