这位兄弟,不是很明白你的意思呀。
在eclipse中,如果要即时编译,在project的Build Automatically项打钩,编写的代码在保存时会进行编译。
如果希望在代码中进行编译,以下几点代码便是:
/**
* Run the compilation.
* @param src 源代码文件
* @return 是否成功
*/
public static boolean compile(String src) {
try {
String [] source = {"-d", clsPath, "-g", src}; Class c = Class.forName("com.sun.tools.javac.Main");
Object compiler = c.newInstance ();
Method compile = c.getMethod ("compile",
new Class [] {(new String [] {}).getClass ()});
int result = ((Integer) compile.invoke
(compiler, new Object[] { source})).intValue ();
System.out.println("compile over");
return (result == 0);
} catch (Exception ex) {
cat.error("CreateRecordView error: \n"+ex);
//System.out.print(ex);
return false;
}
}
在eclipse中,如果要即时编译,在project的Build Automatically项打钩,编写的代码在保存时会进行编译。
如果希望在代码中进行编译,以下几点代码便是:
/**
* Run the compilation.
* @param src 源代码文件
* @return 是否成功
*/
public static boolean compile(String src) {
try {
String [] source = {"-d", clsPath, "-g", src}; Class c = Class.forName("com.sun.tools.javac.Main");
Object compiler = c.newInstance ();
Method compile = c.getMethod ("compile",
new Class [] {(new String [] {}).getClass ()});
int result = ((Integer) compile.invoke
(compiler, new Object[] { source})).intValue ();
System.out.println("compile over");
return (result == 0);
} catch (Exception ex) {
cat.error("CreateRecordView error: \n"+ex);
//System.out.print(ex);
return false;
}
}
具体文档到网站
http://www.beanshell.org/