Meaningless Drivel is fun!
The moose likes Servlets and the fly likes Running Ant from a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Running Ant from a Servlet" Watch "Running Ant from a Servlet" New topic

Running Ant from a Servlet

Danish Shaukat
Ranch Hand

Joined: Nov 16, 1999
Posts: 340
Hi !
Any idea how I will run Ant from a servlet.
Basically I want to build an application when the servlet receives a request.
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1873
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...
Akbar Basha R

Joined: Mar 11, 2002
Posts: 23
There is a class called "Project" under 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.
setUserProperty("ant.file", buildfile);
Project can be configured using "ProjectHelper" available in the same package. After creating and configuring a project, start the build, using "executeTarget" method.
subject: Running Ant from a Servlet
It's not a secret anymore!