Return-Path: Mailing-List: contact user-help@ant.apache.org; run by ezmlm Delivered-To: mailing list user@ant.apache.org Received: (qmail 55364 invoked from network); 5 Mar 2003 19:01:53 -0000 Received: from fw.cenquest.com (HELO exchange.cenquest.com) (209.162.199.194) by daedalus.apache.org with SMTP; 5 Mar 2003 19:01:53 -0000 Received: by EXCHANGE with Internet Mail Service (5.5.2653.19) id ; Wed, 5 Mar 2003 11:01:57 -0800 Message-ID: <739E26BD0D92D3118FA0009027D5F00B01503834@EXCHANGE> From: Greg 'Cosmo' Haun To: 'Ant Users List' Subject: RE: Ant calls from JSP Date: Wed, 5 Mar 2003 11:01:57 -0800 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="ISO-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N > 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... <%@ 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

\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 + "
" + env[0] + "
"); 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("" + str + "" + "
"); } else { out.print( str + "
"); } 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( "
" + str + "" ); str = br.readLine(); } br.close(); } catch( java.io.IOException e ) { out.print("Error while executing the process : " + e ); } %>