You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ultra Funkular <fu...@nettaxi.com> on 2002/06/19 03:03:23 UTC

AntStructure differences between api and buildfile usage

Stephen Bodewig (and anyone else),

The output file of the antstructure task varies hugely depending on how it 
was invoked.

If invoked through the api directly, then taskdefs must be added to the 
project instance for dtd information on those classes to be generated.
	try
	{
                 Project project = new Project();
                 Target target = new Target();
                 AntStructure task = new AntStructure();  // 
(AntStructure) project.createNewTask("antstructure");
		try
		{
  			project.addTaskDefinition( "javac", Class.forName( 
"org.apache.tools.ant.taskdefs.javac") );
		}
		catch(Exception e)
		{
		}
		File file = new File("ant2.dtd");
                 task.setOutput( file );
                 target.addTask( task );
                 final String TARGET_NAME = "CreateDTD";
                 target.setName(TARGET_NAME);
                 project.addTarget(TARGET_NAME, target);
                 project.executeTarget(TARGET_NAME);

	}
	catch(BuildException be)
	{
	}



In contrast, if a build file were to simply be:

<?xml version="1.0" encoding="UTF-8" ?>
<project default="dtd"
     name="test"
     basedir="../">
     <target name="dtd">
         <antstructure output="ant2.dtd"/>
     </target>
</project>

Then every task existing in the ant.jar and optional.jar has their DTD 
information generated.  I love this!



How may I achieve the same result using the api?
the workaround is to output a build.xml file, then run ExecOn on it...


All help appreciated :)


Regards,

T Master



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: AntStructure differences between api and buildfile usage

Posted by Ultra Funkular <fu...@nettaxi.com>.
Stefan,

Thank you very much.  Calling project.init() within the api did the 
trick.  No need to generate a buildfile and read it in (slow mo), or 
define taskdefs.


Regards,


T Master



On Wed, 19 Jun 2002 02:11:37 Stefan Bodewig wrote:
> On Tue, 18 Jun 2002, Ultra Funkular <fu...@nettaxi.com> wrote:
> > Stephen Bodewig (and anyone else),
> 
> That would be Stefan, not Stephen.
> 
> > The output file of the antstructure task varies hugely depending on
> > how it was invoked.
> 
> Well, it generates output for all tasks and types defined in the
> project it is part of.  The way you invoke it, there aren't any tasks
> defined.
> 
> You may want to call Project#init before running your AntStructure
> task - init will autoload all built-in and optional task definitions
> (as long as ant.jar and optional.jar are on your classpath).
> 
> Stefan
> 
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: AntStructure differences between api and buildfile usage

Posted by Stefan Bodewig <bo...@apache.org>.
On Tue, 18 Jun 2002, Ultra Funkular <fu...@nettaxi.com> wrote:
> Stephen Bodewig (and anyone else),

That would be Stefan, not Stephen.

> The output file of the antstructure task varies hugely depending on
> how it was invoked.

Well, it generates output for all tasks and types defined in the
project it is part of.  The way you invoke it, there aren't any tasks
defined.

You may want to call Project#init before running your AntStructure
task - init will autoload all built-in and optional task definitions
(as long as ant.jar and optional.jar are on your classpath).

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>