import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
public class CompileAnotherJavaProgram {
public static void main ( String [] a) {
JavaCompiler compiler=ToolProvider.getSystemJavaCompiler();
int compilerResult=compiler.run(null, null, null, "src/packagename/Hello.java");
System.out.println("Compiler Result Code is "+compilerResult);
}
}
public class Hello {
public static void main(String s[]){
System.out.println("Hello");
}
}
output:
Compiler Result Code is 0// only if there is no error
Compiler Result Code is 1// only if there is error
Getting error while compiling the program
ReplyDeletewhich IDE you are using??
Delete