ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg 'Cosmo' Haun <GH...@cenquest.com>
Subject RE: Ant calls from JSP
Date Wed, 05 Mar 2003 19:01:57 GMT
> From: Greg 'Cosmo' Haun [mailto:GHaun@cenquest.com]
> Sent: Wednesday, March 05, 2003 10:50 AM
> We call Ant from JSP by issuing a new java command.  Sample 
> JSP attached.
> 
Appears my attachment was lost, so I'm including it here, sorry...
 

<html>
<body>

<%@ page import="java.io.*" %>
<% /* 
	GENERIC BUILD
	
	(C) 2002, 2003 Cenquest, Inc
	
	Use to call Ant on any build file.
	
	Returns console output and in bold, error output.
	
	Note that classpath and ant.home are hard-wired.
	
	*/

out.print("Starting Build<p>\n");
String buildfile = request.getParameter("buildfile");
String ANT_HOME = request.getParameter("anthome");
String options = request.getParameter("options");
String logfile = request.getParameter("log");
String logtext;
if (options == null) options = "";

if (ANT_HOME == null) ANT_HOME = "c:\\ant-1.5\\";

if (logfile == null) {
	logtext = "";
} else {
	logtext = "-logfile " + ANT_HOME + logfile;
}
String[] env = {""};


if 	(ANT_HOME.substring(1,2).equals(":")) {	
	// must be windows machine	
	env[0] = "CLASSPATH=" + ANT_HOME + "lib\\;" +
//unjarred tasks
					ANT_HOME + "lib\\ant.jar;" +
					ANT_HOME + "lib\\optional.jar;" +
					ANT_HOME + "lib\\xercesImpl.jar;" +
					ANT_HOME + "lib\\xml-apis.jar;" +
					ANT_HOME + "lib\\NetComponents.jar;"
+	//FTP and TELNET
					ANT_HOME + "lib\\jswf.jar;" +
//jpeg2swf
					"";
} else {
	// linux or mac os x
	env[0] = "CLASSPATH=" + ANT_HOME + "lib/:" + 
					ANT_HOME + "lib/ant.jar:" +
					ANT_HOME + "lib/optional.jar:" +
					ANT_HOME + "lib/xercesImpl.jar:" +
					ANT_HOME + "lib/xml-apis.jar:" +
					ANT_HOME + "lib/NetComponents.jar:"
+
					"";
}

String execline = 	"java " +
					"-Dant.home=" + ANT_HOME + " " +
					"org.apache.tools.ant.Main " +
					"-verbose " +
					logtext +
					" -buildfile " + buildfile +
					" " + options +
					"";


Runtime runTime = Runtime.getRuntime();					
Process myProcess = runTime.exec(execline, env);
out.println(execline + "<br>" + env[0] + "<br>");
out.flush();

//Print out non-error messages
try {
      InputStreamReader inReader = new InputStreamReader(
myProcess.getInputStream() );
	  BufferedReader br = new BufferedReader( inReader );
      String str;
	  str = br.readLine();
	  int linecounter = 0;
	  while ( str != null ){
	  	if (linecounter % 4 == 0) {
	  		out.flush();
	  	}
	  	if (str.endsWith(":") && !str.equals("mytimestamp:") &&
(str.indexOf("[") == -1)) {
	  		out.print("<b>" + str + "</b>" + "<br>");
	  	} else {
			 out.print( str + "<br>");
		}
		str = br.readLine();
		linecounter++;
	  }
      br.close();
}	  
catch( java.io.IOException e ) {
      out.print("Error while executing the process : " + e );
}

//Print out error messages
try {
	  InputStreamReader inReader = new InputStreamReader(
myProcess.getErrorStream() );
	  BufferedReader br = new BufferedReader( inReader );
	  String str;
	  str = br.readLine();
	  while ( str != null ){
	  
		 out.print( "<br><b>" + str + "</b>" );
		 str = br.readLine();
	  }
	  br.close();
}	  
catch( java.io.IOException e ) {
	  out.print("Error while executing the process : " + e );
}

%> 
</body></html>

Mime
View raw message