wood burning stoves 2.0*
The moose likes JSP and the fly likes How can I start Ant from a JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How can I start Ant from a JSP?" Watch "How can I start Ant from a JSP?" New topic
Author

How can I start Ant from a JSP?

Kevin Crocker
Greenhorn

Joined: Sep 06, 2002
Posts: 20
I want to be able to run an ant task from my jsp. Is this possible?
Kevin Crocker
Greenhorn

Joined: Sep 06, 2002
Posts: 20
I have done some looking around and tried this in my jsp.
<%
out.print("<p><b>Running ant remotebuild</b>");
try {
Process remoteBuild = null;
String cmdline = "cmd.exe /E:1900 /C ant.bat -f c:\\build.xml remoteBuild";
remoteBuild = Runtime.getRuntime().exec(cmdline);
}catch (Exception e){
out.print("Error trying to build cogent : " + e.getMessage());
}
%>
but it still does not work. Please help!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
"Didn't work" is not much help. What actually happened?
You should study the requirements for using exec - in many cases you have to get the process and consume the process output stream. See the java.lang.Process documentation.
I suggest you make a simple JavaBean to test this offline rather than writing code in a JSP.
Bill
Kevin Crocker
Greenhorn

Joined: Sep 06, 2002
Posts: 20
The jsp page that spawns this process displays as expected but the ant task never executes. I know this because the task sends out an email on the success/failure of the build.
I can cut and paste the cmd string into the console and it will run correctly and I get the email.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
If the ant task sends any output to the console, you will have to have the Process consume the Ant output stream. Otherwise Ant hangs trying to send output. Like I said, study the java.lang.Process documentation.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I start Ant from a JSP?