• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Running Ant from Console App

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joe !
My problem is solved.
Danish
[ February 25, 2004: Message edited by: Danish Shaukat ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic