ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Turner <j...@socialchange.net.au>
Subject Re: Calling Ant from a JSP page
Date Thu, 13 Sep 2001 12:05:46 GMT
On Wed, Sep 12, 2001 at 11:44:25AM -0700, Massa, Ray wrote:
> Has anyone successful called Ant from a JSP page?

Yes, I'm calling Ant from a JSP for a project now.

I started by following the advice in the javadocs for
org.apache.tools.ant.Main:
  
  "If you integrating Ant into some other tool, this is not the class to use as
  an entry point. Please see the source code of this class to see how it
  manipulates the Ant project classes."

After about 2 days of wasted effort, I gave up. JDD never actually tried doing 
this; if he had, he'd have made more private and package-scoped methods public
;) It's obviously possible, but not by mere mortals with deadlines to meet.

I would appreciate it if proponents of "doing it properly" either provide code
to demonstrate how to embed Ant (with all command-line functionality intact), 
or remove that (IMHO) misleading comment.

Save yourself a lot of trouble and take the quick'n'dirty approach of tools
like cruise control[1]; simply invoke org.apache.tools.ant.Main. You need to
set a SecurityManager just before, to prevent System.exit() killing your VM.

Another thing that bit me; synchronize your Ant call. If you don't, you'll get
NPEs deep in Ant code which (for some reason) kill Tomcat 3.2.x.

Anyway, I've wrapped up all the above into a little project, at:

http://newgate.socialchange.net.au/~jeff/apache/jakarta/jakarta-ant/antrunner/

It uses the SecurityManager classes from cruisecontrol. There's an example JSP
in that directory too, which shows how to log the build info to an XML file in
the current dir. You can then use the log.xsl bundled with Ant to present it to
the user.

HTH,

--Jeff

[1] http://cruisecontrol.sourceforge.net/



> thanks
> 
> ray

Mime
View raw message