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/21 02:15:52 UTC

Calling Ant from a JSP Page (2)

First thanks for all the responses the first time! 

What I'm trying to do:

Call Ant from a JSP page. I created a JSP page that runs on Tomcat, with an
HTML text link that calls a Servlet with the following code:

try        {

PrintWriter out = res.getWriter();

out.write("step 1");            // debug

Process p = Runtime.getRuntime().exec("c:\\ant\\bin\\ant.bat -buildfile
c:\\ant\\bin\\build.xml -logfile c:\\ant\\bin\\foo.txt"); 

out.write("step 2");            // debug

out.flush();

out.print("<html><head><META HTTP-EQUIV='Refresh'
CONTENT='0;URL=http://localhost:8080/foo.jsp?QProjName=foobar></head><body><
/body></html>");

out.close(); <?xml:namespace prefix = o ns =
"urn:schemas-microsoft-com:office:office" />

} catch (IOException ex){

                        throw new ServletException("IOException: " +
ex.toString())

            }

The output of the page is "step 1setp 2". There are NO errors that I could
find-checked Java Console, Tomcat DOS window, all logs in
<tomcat_home>\logs. My guess is the output is causing problems. Can someone
suggest an easy want to encapsulate the output for ease of debugging?

The build.xml files calls Windows Command.com to execute a source safe batch
file. The batch file opens a project and gets (saves to local drive) all the
files from the project.

I can successfully run the string in the .exec(minus the extra '\''s) from
Run or an MS-DOS box.

Could someone suggest a cleaner way of doing this? 

Will there be an ANT API?

Thanks!


Re: Calling Ant from a JSP Page (2)

Posted by Jeff Turner <je...@socialchange.net.au>.
On Thu, Sep 20, 2001 at 05:15:52PM -0700, Massa, Ray wrote:
> First thanks for all the responses the first time! 
> 
> What I'm trying to do:
[..]
> Process p = Runtime.getRuntime().exec("c:\\ant\\bin\\ant.bat -buildfile
> c:\\ant\\bin\\build.xml -logfile c:\\ant\\bin\\foo.txt"); 

Ew. Why not just call org.apache.tools.ant.Main() directly?

Example at:

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

--Jeff

Re: Calling Ant from a JSP Page (2)

Posted by T Master <tm...@iknowledgeinc.com>.
There already is an Ant API!!!!
Download the source, and accompanying javadocs.



----- Original Message -----
From: "Massa, Ray" <RM...@ea.com>
To: <an...@jakarta.apache.org>
Sent: Thursday, September 20, 2001 6:15 PM
Subject: Calling Ant from a JSP Page (2)


> First thanks for all the responses the first time!
>
> What I'm trying to do:
>
> Call Ant from a JSP page. I created a JSP page that runs on Tomcat, with
an
> HTML text link that calls a Servlet with the following code:
>
> try        {
>
> PrintWriter out = res.getWriter();
>
> out.write("step 1");            // debug
>
> Process p = Runtime.getRuntime().exec("c:\\ant\\bin\\ant.bat -buildfile
> c:\\ant\\bin\\build.xml -logfile c:\\ant\\bin\\foo.txt");
>
> out.write("step 2");            // debug
>
> out.flush();
>
> out.print("<html><head><META HTTP-EQUIV='Refresh'
>
CONTENT='0;URL=http://localhost:8080/foo.jsp?QProjName=foobar></head><body><
> /body></html>");
>
> out.close(); <?xml:namespace prefix = o ns =
> "urn:schemas-microsoft-com:office:office" />
>
> } catch (IOException ex){
>
>                         throw new ServletException("IOException: " +
> ex.toString())
>
>             }
>
> The output of the page is "step 1setp 2". There are NO errors that I could
> find-checked Java Console, Tomcat DOS window, all logs in
> <tomcat_home>\logs. My guess is the output is causing problems. Can
someone
> suggest an easy want to encapsulate the output for ease of debugging?
>
> The build.xml files calls Windows Command.com to execute a source safe
batch
> file. The batch file opens a project and gets (saves to local drive) all
the
> files from the project.
>
> I can successfully run the string in the .exec(minus the extra '\''s) from
> Run or an MS-DOS box.
>
> Could someone suggest a cleaner way of doing this?
>
> Will there be an ANT API?
>
> Thanks!
>
>