• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I start Ant from a JSP?

 
Kevin Crocker
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to be able to run an ant task from my jsp. Is this possible?
 
Kevin Crocker
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic