You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Massa, Ray" <RM...@ea.com> on 2001/09/12 20:44:25 UTC
Calling Ant from a JSP page
Has anyone successful called Ant from a JSP page?
thanks
ray
Re: Calling Ant from a JSP page
Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Jeff Turner wrote:
>
> 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.
The comment is not misleading - it is entirely right and running Main
inside a server will most likely upset the server in some way. At the
very least it will cause the server's system.out to be directed into
Ant's event system. Not too cool.
I agree that the access levels on some of this stuff makes it difficult
and that should be addressed (I will try to address soon, but patches
are welcome in the meantime).
>
> Save yourself a lot of trouble
But do so with the knowledge that it is not recommended. If it all goes
pear-shaped, you'll know why.
Conor
Re: Calling Ant from a JSP page
Posted by Jeff Turner <je...@socialchange.net.au>.
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
RE: Calling Ant from a JSP page
Posted by "Carter A. Thompson" <ca...@voxeo.com>.
I have a JSP page that runs a Perl script that calls Ant. In
your case I suppose you could just substitute the perl script for
an Ant call directly.
In your JSP Page use something like this:
Process myProc = Runtime.getRuntime().exec("cmd /c ant");
or for Unix use one of the various shells at your disposal:
Process myProc = Runtime.getRuntime().exec("sh ant");
Hope this helps.
Cheers,
Carter.
> -----Original Message-----
> From: Massa, Ray [mailto:RMassa@ea.com]
> Sent: Wednesday, September 12, 2001 11:44 AM
> To: 'ant-user@jakarta.apache.org'
> Cc: 'rmassa@quarium.com'
> Subject: Calling Ant from a JSP page
>
>
> Has anyone successful called Ant from a JSP page?
>
> thanks
>
> ray