package com.aaa.bbb;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class GetProperty {
public static final String SUN_BOOT_CLASS_PATH = "sun.boot.class.path";
public static final String JAVA_EXT_DIRS = "java.ext.dirs";
public static final String JAVA_CLASS_PATH = "java.class.path";
public void print(String ss) {
System.out.println("Im ok!" + ss);
}
@SuppressWarnings("unchecked")
public static void main(String args[]) throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException {
System.out.println(GetProperty.SUN_BOOT_CLASS_PATH + " = " + System.getProperty(GetProperty.SUN_BOOT_CLASS_PATH));
System.out.println(GetProperty.JAVA_EXT_DIRS + " = " + System.getProperty(GetProperty.JAVA_EXT_DIRS));
System.out.println(GetProperty.JAVA_CLASS_PATH + " = " + System.getProperty(GetProperty.JAVA_CLASS_PATH));
Class getp = Class.forName("com.aaa.bbb.GetProperty");
Class[] argTypes = new Class[]{String.class};
Method m = getp.getMethod("print", argTypes);
m.invoke(Thread.currentThread().getContextClassLoader().loadClass("com.aaa.bbb.GetProperty").newInstance(), "aaaa");
}
}
classloader
最新推荐文章于 2021-02-19 10:54:31 发布