Monday, October 11, 2010

In Java , programeticlly how to Compile and create JAR?

For Compilation

// import
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

try {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

// set ur java file path
int result = compiler.run(null, null, null, "BaseClass/Hello.java");
}
catch(Exception e)
{
e.printStackTrace();
}


For Jar creation

try {
String command = "jar cvf MyFirst.jar BaseClass" + File.separatorChar;
Process p = Runtime.getRuntime().exec(command);
}
catch (Exception ex) {
ex.printStackTrace();
}

No comments:

Post a Comment