ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ion" <vnhu38...@subdimension.com>
Subject Re: Running Ant from Java
Date Thu, 12 Sep 2002 09:48:34 GMT
Well folks, I worked it out, courtesy of this page:

http://www.onjava.com/pub/a/onjava/2002/07/24/antauto.html?page=1


This is the code I used to acheive the objectives oulined in the
previous message:

--------------------------------------------------------------------
      Project project = new Project();
      project.init();
      DefaultLogger logger = new DefaultLogger();
      logger.setMessageOutputLevel(Project.MSG_INFO);
      logger.setErrorPrintStream(System.err);
      logger.setOutputPrintStream(System.out);
      project.addBuildListener(logger);

      File buildFile = new File("buildhtml.xml");
      ProjectHelper.configureProject(project, buildFile);
      project.setProperty("ant.file", buildFile.getAbsolutePath());
      project.setProperty("item", "ant");
      project.setProperty("inputdir", "src/items/ant");
      project.setProperty("outputdir", "build/items/ant");
      project.setProperty("graphics.prefix", "../../");
      try {
         project.executeTarget("checkifuptodate");
      } catch(Exception e) {System.err.println(e.getMessage());}
      // rest of program goes here
--------------------------------------------------------------------

Pretty cool huh! ;)

+-----+
 |  ion  |
+-----+

----- Original Message -----
From: "ion" <vnhu38f93@subdimension.com>
To: <ant-user@jakarta.apache.org>
Sent: Wednesday, September 11, 2002 3:03 PM
Subject: Running Ant from Java


> I have written a number of Ant 'functions' like this:
>
> --------------------------------------------------------------------------
--
> -----------
> <project name="buildhtml" default="buildhtml">
>   <!-- PARAMETERS
>     item      - The identification name of the item.
>     inputdir  - The directory where the item's source xml is located.
>     outputdir - The directory where one desires the output html to go.
>     graphics.prefix - The prefix to where callout graphics and admonitions
> are located, e.g (../../)
>   -->
>   <target name="buildhtml" description="Builds HTML output for an item">
>     <!-- Load in properties -->
>     <loadproperties srcFile="ant.properties"/>
>     <available file="${inputdir}/files" type="dir"
> property="files.available"/>
>
>     <antcall target="copyfiles"/>
>
>     <exec executable="java">
>       ...
>     </exec>
>
>     <copy file="${inputdir}/${item}.xml"
tofile="${outputdir}/${item}.xml"/>
>   </target>
>
>   <target name="copyfiles" if="files.available" description="Copies needed
> files">
>     <echo>Copying required files for ${item} from ${inputdir} to
> ${outputdir}</echo>
>     <copy todir="${outputdir}/files"><fileset
> dir="${inputdir}/files"/></copy>
>   </target>
> </project>
> --------------------------------------------------------------------------
--
> -----------
>
> I would like to call them from Java programs by simply setting the
> properties
> that correspond to the parameters mentioned at the top.
>
> I have been messing around trying to do this for a few hours now and it is
> doing my head in, any help would be greatly appreciated.
>
> I preferably want the output from the programs to goto stdout and stderr
> as normal. I want to do something like this:
>
> Ant ant = new Ant();
> ant.setProperty("item", "blahblah");
> ant.setProperty("inputdir", "blahblah");
> ant.setProperty("outputdir", "blahblah");
> ant.setAntfile("buildhtml.xml");
> ant.execute();
>
> from within a Java program and have program control return to the line
> after the call to the ant file.
>
> Regards
>
> [[[']]]
> | ion |
> [[[']]]
>
>
> --
> To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message