running build.xml from java program
i am trying to run ant script from java program.what is the procedure to execute the program How to run build.xml from java program?
here is how iam trying to implement
Process proc = rt.exec("ant -buildfile D:ant\\trail");
regards,开发者_开发知识库 techie
Check here Execute Ant From Your Application and look at this example:
Project project = new Project();
project.init();
DefaultLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setErrorPrintStream(System.err);
logger.setOutputPrintStream(System.out);
project.addBuildListener(logger);
File buildFile = new File("buildhtml.xml");
ProjectHelper.configureProject(project, buildFile);
project.setProperty("ant.file", buildFile.getAbsolutePath());
project.setProperty("item", "ant");
project.setProperty("inputdir", "src/items/ant");
project.setProperty("outputdir", "build/items/ant");
project.setProperty("graphics.prefix", "../../");
try {
project.executeTarget("checkifuptodate");
} catch(Exception e) {System.err.println(e.getMessage());}
// rest of program goes here
It is a better solution than calling Runtime.exec
Rather than trying to start a windows executable separately, it'd be a more robust and flexible solution to use the Ant API. Docs are included with ant itself, they are not online...
Try Runtime.getRuntime().exec("cmd /c start ant.bat");
taken from How do I run a batch file from my Java Application?
精彩评论