Return-Path: Mailing-List: contact user-help@ant.apache.org; run by ezmlm Delivered-To: mailing list user@ant.apache.org Received: (qmail 23677 invoked by uid 500); 10 Feb 2003 20:47:39 -0000 Received: (qmail 23615 invoked from network); 10 Feb 2003 20:47:38 -0000 Received: from smtp04.iprimus.com.au (210.50.76.52) by daedalus.apache.org with SMTP; 10 Feb 2003 20:47:38 -0000 Received: from smtp02.iprimus.net.au (210.50.76.70) by smtp04.iprimus.com.au (6.7.010) id 3E41F723000A1AAD for ant-user@jakarta.apache.org; Tue, 11 Feb 2003 07:26:57 +1100 Received: from galahad.compuserve.com ([210.50.56.137]) by smtp02.iprimus.net.au with Microsoft SMTPSVC(5.0.2195.5600); Tue, 11 Feb 2003 07:26:55 +1100 Message-Id: <5.1.0.14.0.20030211062309.026e95f8@pop.compuserve.com> X-Sender: tonyob@pop.compuserve.com X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Tue, 11 Feb 2003 06:26:48 +1000 To: "Ant Users List" From: Tony Obermeit Subject: Re: Running build.xml located in jar file In-Reply-To: <50DD2632-2655-11D7-B7A0-000393A564E6@ehatchersolutions.com > References: <5.1.0.14.0.20030112054244.024c6c08@pop.compuserve.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-OriginalArrivalTime: 10 Feb 2003 20:26:55.0870 (UTC) FILETIME=[C12B91E0:01C2D142] X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Some time ago Erik replied to this post, in the skeleton he referenced, (listed below), the code loads the project from a file and runs it. My question is this, I typically run ant specifying a propertyfile on the command line argument, how can I get the programmatic invocation of ant to recognize / load the properties from a file. I can't specify the property file within the build script for a variety of reasons. By the way, Erik, thanks for the work you put in to the "Java Development with Ant" book, it has been a great help!!! >But it seems folks should be integrating with Ant by emulating what >Main.main does rather than simply invoking it directly. I've toyed with >writing a servlet that ran Ant once upon a time. I just dug up the code >and here it is: > > final Project project = new Project(); > AntListener listener = new AntListener(); > project.addBuildListener(listener); > File buildFile = new File(buildFile); > > Throwable exception = null; > try { > project.fireBuildStarted(); > project.init(); > ProjectHelper.configureProject(project, buildFile); > project.executeTarget(project.getDefaultTarget()); > } > catch (BuildException e) { > exception = e; > } > finally { > project.fireBuildFinished(exception); > > Writer out = response.getWriter(); > out.write(listener.getLog()); > } > >AntListener is just a BuildListener implementing class that collects all >the log messages for grabbing later (in the finally clause). This is >just a simple example, and one that probably needs lots of improvement >to be solid, but its better than calling Main.main, IMO. > > Erik At 12:43 PM 12/01/2003 -0500, you wrote: >To do it programmatically, I'd recommend you just emulate what Main.main() >does in your own class. See a post I made providing a basic skeleton of >Java code to run an Ant project from a servlet from a couple of weeks ago >(or so). You wouldn't do it as a java.io.File (at least not without >refactoring Ant). You'd first pull a resource from a JAR (or URL) to a >local filesystem file, then run that through Ant's existing mechanisms. > > Erik > > > >On Saturday, January 11, 2003, at 02:44 PM, Tony Obermeit wrote: >>Thanks for the quick reply, >> >>Is it possible to do this programmatically? I can then reference the >>build file and pass it to the ant.Main class as a java.io.File object? >> >>Tony >> >>At 05:32 AM 11/01/2003 -0500, you wrote: >>>Currently Ant only runs a build file located on the filesystem. >>> >>>A workaround would be to ship with a minimal build.xml along with the >>>JAR which does an to bootstrap and the primary build file, >>>although this is probably just as good as deploying the real build file. >>> >>>It would be nice for Ant to be modified to allow getting at build files >>>from an archive resource or from a URL. >>> >>> Erik >>> >>> >>>On Saturday, January 11, 2003, at 12:51 AM, Tony Obermeit wrote: >>>>I have created a jar file that include the ant class files, a build.xml >>>>file and my application class files. >>>> >>>>I have not been able to get ant to find the build file within the jar >>>>file. If I place the build file in the same directory as the jar file, >>>>and run ant as follows: >>>> >>>>java -cp application.jar org.apache.tools.ant.Main, ant runs the build >>>>file successfully. The problem is when the build file is not in a >>>>directory, but instead is bundled within the jar file, then ant reports >>>>"Build file: build.xml does not exist, Build Failed". >>>> >>>>I'm using a single jar file (which includes ant class files, >>>>application class files and build.xml) so that my entire application, >>>>and it's setup scripts (build.xml) can be easily deployed. For what >>>>it's worth, the build file contains sql tasks that I used to create >>>>database tables when running the application. >>>> >>>>Any help would be appreciated. >>>> >>>>Thanks >>>> >>>>Tony >>>> >>>> >>>> >>>>-- >>>>To unsubscribe, e-mail: >>>> >>>>For additional commands, e-mail: >>> >>> >>>-- >>>To unsubscribe, e-mail: >>> >>>For additional commands, e-mail: >> >> >> >> >>-- >>To unsubscribe, e-mail: >> >>For additional commands, e-mail: >> > > >-- >To unsubscribe, e-mail: >For additional commands, e-mail: