• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Ant from Console App

 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
I am trying to run Ant from my console application. I don't want to use
a batch file. I am having problems with my command and need some help.
My build script is in D:\apps\serverapps
And here is the command
String[] cmd = new String[4];
cmd[0] = "cmd.exe" ;
cmd[1] = "/c" ;
cmd[2] = "cd d:\\apps\\serverapps";
cmd[3]="ant";
I am getting the following error message:
"The system cannot find the path specified".
If I don't specify the fourth array element or fourth command then I dont get any error. But on specifying the fourth command I get error, be it "ant" or "cd" or "dir".
Danish
[ February 25, 2004: Message edited by: Danish Shaukat ]
 
Joe Ess
Bartender
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The array passed to exec() should contain the command-line tokens of a single command, not a list of commands (i.e. "CD" and "ant"). You can't change the working directory using "CD" anyway, since it will be invoked in a seperate process. Check out the java.lang.Runtime documentation. There's a couple of exec() methods that take the working directory as an argument or you could probably get away with passing the full path of the build.xml file to ant if you used full (not local) paths in it.
 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe !
My problem is solved.
Danish
[ February 25, 2004: Message edited by: Danish Shaukat ]
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By doing such a thing, you are breaking one of the design intentions of Ant - to remain platform independant.
Why aren't you calling on the Ant APIs to start a build ?
Those APIs were exposed for that exact reason.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic