On Mon, Oct 25, 2010 at 11:19 AM, Kevin Connor Arpe <kevina...@gmail.com> wrote:
> I wrote a StackOverflow.com post, but was unable to get help on this issue.

SO is great, but the official user and dev lists is the best place to
ask Ant questions.

> <?xml version="1.0" encoding="UTF-8"?>
> <project name="MyTask" basedir="." default="init">
>   <target name="init"
>           description="test the custom task"
>   >
>      <taskdef name="CustomTask1"
>               classname="AntCustomTask1"
>               classpath="C:\my_custom_ant_task_class_files"
>      />
>      <taskdef name="CustomTask2"
>               classname="AntCustomTask2"
>               classpath="C:\my_custom_ant_task_class_files"
>      />
>      <CustomTask1/>
>      <CustomTask2/>
>   </target>
> </project>
>
> Do all of the above and you will see "alloc" logged twice. I cannot
> get these two custom tasks to share the "big data".

Because each is loaded thru a different class loader, and there's a
different static member per "independent" class loader. If you are new
to Java, class loaders is a very interesting advanced topic to look
into btw :)

I don't remember the details, but it's likely your two independent
<taskdef> that force using separate class loaders. Using either a
single taskdef loading a .properties file, or using a classpathref
might use the same classloader instead. Also putting your tasks into
an AntLib in its own Jar with a proper antlib.xml manifest would also
likely use a single class loader.

But as Jeffrey wrote, you could have your tasks read/write properties
to communicate, or pass them a reference to a datatype instance as
well.

<mytype id="foo" ... > ... </mytype>
<mytask1 mytyperef="foo">...</mytask1>
<mytask2 >
  <mytype ref="foo" /> <!-- or is it idref? I don't recall the naming
convention -->
  ...
</mytask2>

Trouble is, reference-handling in task is not implicit, you have to
manually code it in, and there are many examples in the code. Note the
two ways references are passed to tasks typically, via a xyzref
attribute, or a nested xyz with only a ref (or idref?) attribute.

Hope this help. Sorry my Ant is getting very rusty. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ant.apache.org
For additional commands, e-mail: dev-h...@ant.apache.org

Reply via email to