Private static com.sun.tools.javac.Main javac = new com.sun.tools.javac.Main();
String[] args = new String[] {“-d”, System.getProperty(“user.dir”),filename };
Int status = javac.compile(args);
try {
// 访问这个类
Class cls = Class.forName(classname);
//调用main方法
Method main = cls.getMethod(“main”, new Class[] { String[].class });
main.invoke(null, new Object[] { new String[0] });
}catch (SecurityException se) {
debug(“access to the information is denied:” + se.toString());
}catch (NoSuchMethodException nme) {
debug(“a matching method is not found or if then name is <init> or <clinit>:
” + nme.toString());
}catch (InvocationTargetException ite) {
debug(“Exception in main: ” + ite.getTargetException());
}catch (Exception e){
debug(e.toString());
}
Please input java code:
for(int i=0;i<10;i++){System.out.println(“this is:”+i);}
wait....
--------------------
this is:0
this is:1
this is:2
this is:3
this is:4
this is:5
this is:6
this is:7
this is:8
this is:9