user2400582
user2400582

Reputation: 137

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

   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 ?

Upvotes: 0

Views: 49

Answers (1)

Muhammad Hamed
Muhammad Hamed

Reputation: 1239

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.

Upvotes: 1

Related Questions