我想从java程序运行ant脚本。什么是程序执行程序 如何从java程序运行build.xml?从java程序运行build.xml
这里是如何IAM试图执行
Process proc = rt.exec("ant -buildfile D:ant\\trail");
问候, 技术人员
我想从java程序运行ant脚本。什么是程序执行程序 如何从java程序运行build.xml?从java程序运行build.xml
这里是如何IAM试图执行
Process proc = rt.exec("ant -buildfile D:ant\\trail");
问候, 技术人员
尝试Runtime.getRuntime().exec("cmd /c start ant.bat");
从How do I run a batch file from my Java Application?
入住这里Execute Ant From Your Application 采取看看这个例子:
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
它比调用Runtime.exec
而不是试图单独启动一个Windows可执行一个更好的解决方案,这将会是使用Ant的API一个更强大和灵活的解决方案。文件包含在蚂蚁本身中,它们是not online ...
win/* nix系统? –
windows和eclipse – techie
如果你有eclipse,那么为什么从java调用它? –