• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How to execute ant command from a java program using runtime.exec()?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
web/scripts dir has a build.xml and command 'ant -Dname=xxx register' executes properly from Linux command prompt. I am trying to execute the same from my java code. Following is the code snippet for the quick reference. And it throws exception saying 'ant' not found.

File wd = new File("/web/scripts");
Process proc = null;
try {
proc = Runtime.getRuntime().exec("ant -Dname=xxx register", null, wd);
} catch (Exception e) {
}

I even tried passing command as String[] cmd = {"ant", "-Dname=xxx", "register"} but no use.
I have even tried using absolute path for the ant command "/urs/local/apache-ant-1.7.0/ant......" but no use.
Do you any of you guys know how to handle this? please help me out. thanks

webapp is in /web/tomcat/base/current/webapps
ant is installed in /urs/local/apache-ant-1.7.0... $ANT_HOME points to this director.
build.xml is in /web/scripts
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

So, what is the error message that you get?
 
labi laba
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot....

if i use 'ant -Dname=xxx register" --- throws ant not found even though i have ant.jar in my build path

for all others, its a null pointer exception
 
Ranch Hand
Posts: 121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need the $ANT_HOME/bin folder to be in the PATH

tha 'ant' that you call in the command line is not from the ant.jar, but a shell script (.bat in windows) that you set some environment variables and call tha proper java command to run Ant
[ April 14, 2008: Message edited by: R Lopes ]
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic