• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Ant from a Servlet

 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
Any idea how I will run Ant from a servlet.
Basically I want to build an application when the servlet receives a request.
Danish
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Danish
I guess you are looking for Runtime.exec() functionality...basically you would do something like,
Runtime r = Runtime.getRuntime();
r.exec(new String[]{"/usr/bin/ant","<<your target>>"});
Note that I am using the String[] argument method as that is the good way I guess to invoke commands as the String argument method causes confusions sometimes and doesn't do what we want..I always go with String[] method..
google more for how to use exec() from java...
Regards
Maulin
 
Akbar Basha R
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
There is a class called "Project" under org.apache.tools.ant package available along with ant libraries.
you will be able to create a project and assign the build xml file for a specific build, using "Project" class.
The following methods in Project class can be used to create a project.
init();
setUserProperty("ant.file", buildfile);
executeTarget(target);
Project can be configured using "ProjectHelper" available in the same package. After creating and configuring a project, start the build, using "executeTarget" method.
-Akbar
SCJP
SCWCD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic