Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@apache.org Received: (qmail 39741 invoked from network); 17 Sep 2002 14:48:28 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 17 Sep 2002 14:48:28 -0000 Received: (qmail 27698 invoked by uid 97); 17 Sep 2002 14:48:57 -0000 Delivered-To: qmlist-jakarta-archive-ant-user@jakarta.apache.org Received: (qmail 27652 invoked by uid 97); 17 Sep 2002 14:48:56 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 27640 invoked by uid 98); 17 Sep 2002 14:48:56 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: Running ant from Java Date: Tue, 17 Sep 2002 17:48:14 +0300 Message-ID: <9B7503C54251174CBD7A79FA0DF6BC4F011506C7@esebe016.ntc.nokia.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Running ant from Java Thread-Index: AcJeUYurV3F3O8oUEdanaAAGW4dIBwABoamwAABGd8A= From: To: X-OriginalArrivalTime: 17 Sep 2002 14:48:15.0105 (UTC) FILETIME=[40BD6710:01C25E59] X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Thanks Daniel. I'll give it a try. /G=F6ran > -----Original Message----- > From: ext Daniel L. Boxwell [mailto:BoxwellDL@C-IV.org] > Sent: 17. September 2002 17:42 > To: Ant Users List > Subject: RE: Running ant from Java >=20 >=20 > Here is an admittedly ugly class that I whipped together=20 > once. You will want to clean it up and customize it for your=20 > purposes, but it should get you started.=20 >=20 > --Dan >=20 > import org.apache.tools.ant.Project; > import org.apache.tools.ant.Target; > import org.apache.tools.ant.BuildLogger; > import org.apache.tools.ant.DefaultLogger; > import org.apache.tools.ant.ProjectHelper; > import org.apache.tools.ant.taskdefs.Echo; >=20 > import java.io.File; > import java.io.PrintStream; > import java.io.ByteArrayOutputStream; > import java.util.Vector; > import java.util.HashMap; > import java.util.Iterator; >=20 > public class AntLauncher > { > =09 > public static String run( HashMap args )=20 > {=20 > final Project project =3D new Project(); > ByteArrayOutputStream out =3D null; > =20 > try > { > out =3D new ByteArrayOutputStream(); > =20 > project.addBuildListener(AntLauncher.createLogger( out ));=20 > project.init();=20 > File buildFile =3D new File(=20 > (String)args.remove("ant.file") ); > ProjectHelper.configureProject(project, buildFile); > String path =3D buildFile.getAbsolutePath(); > =20 > // Set Build File > project.setUserProperty("ant.file", path); > =20 > // Set runtime properties > Iterator iterator =3D args.keySet().iterator(); > while ( iterator.hasNext() ) > { > String key =3D (String)iterator.next(); > String value =3D (String)args.get( key ); > project.setUserProperty( key, value ); =20 > } > =20 > Vector targets =3D new Vector(5);=20 > Target init =3D new Target(); > init.setName("echo"); > init.setProject(project); > String myTarget =3D project.getDefaultTarget(); > targets.addElement( myTarget ); > Echo echo =3D new Echo(); > echo.setMessage("Trying to Run ant using java."); > init.addTask(echo); > project.addTarget(init); > project.executeTargets(targets); > }=20 > catch (RuntimeException exc )=20 > { > exc.printStackTrace(); > }=20 > =20 > return out.toString(); > } > =09 > /** > * Creates the default build logger for sending build=20 > events to the ant log. > */ > private static BuildLogger createLogger(=20 > ByteArrayOutputStream out ) > { > BuildLogger logger =3D null; > logger =3D new DefaultLogger(); >=20 > logger.setMessageOutputLevel(Project.MSG_INFO); > logger.setOutputPrintStream(new PrintStream( out )); > logger.setErrorPrintStream(new PrintStream( out )); > logger.setEmacsMode(false); >=20 > return logger; > } > } >=20 >=20 >=20 >=20 > -----Original Message----- > From: Ext-Goran.Westin@nokia.com [mailto:Ext-Goran.Westin@nokia.com] > Sent: Tuesday, September 17, 2002 6:53 AM > To: ant-user@jakarta.apache.org > Subject: Running ant from Java >=20 >=20 > Hi >=20 > Has anyone written a class that has a method that can run Ant=20 > from a Java class. The methods in org.apache.tools.ant.Main=20 > all calls "System.exit()" and hence cannot be used for this purpose. >=20 > /G=F6ran >=20 > -- > To unsubscribe, e-mail: =20 For additional commands, e-mail: = -- To unsubscribe, e-mail: = For additional commands, e-mail: = -- To unsubscribe, e-mail: For additional commands, e-mail: