简体   繁体   English

从Java代码运行时如何将参数传递给ant脚本?

[英]How to pass argument to ant script while running from java code?

I want to execute an antscript from java program with arguments, example: ant -f myantscript.xml -dir \\my\\path\\dir .I am able to run without arguments like this 我想从带参数的Java程序中执行一个脚本,例如:ant -f myantscript.xml -dir \\ my \\ path \\ dir。我可以在没有参数的情况下运行

   File buildFile = new File("build.xml");
   Project p = new Project();
   p.setUserProperty("ant.xml", buildFile.getAbsolutePath());
   p.init();
   ProjectHelper helper = ProjectHelper.getProjectHelper();
   p.addReference("ant.projectHelper", helper);
   helper.parse(p, buildFile);
   p.executeTarget(p.getDefaultTarget());

which function can i use to set arguments ? 我可以使用哪个函数设置参数?

You can set it as a system property 您可以将其设置为系统属性

Properties props = System.getProperties();
props.setProperty("build.dir", "build");

Or 要么

System.setProperty("build.dir", "build");

I hope this could help. 我希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM