You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Mariano Benitez <ma...@fuegolabs.com> on 2004/05/07 16:14:27 UTC

antlibs and classloaders #2

I am at the edge of a mental crisis, I need help....


Can someone explain how antlib paths and tasks works, I have this 
situation that I cannot understand.


I defined this:

<project name="fuego.internal.test.include" basedir=".">

    <property name="xml.encoding" value="ISO-8859-1"/>
   
    <path id="fuego.internal.test.antlibs.path">
        <fileset dir="${fuego.basedir}/lib">
            <include name="fuegoexpress-antlib.jar"/>
            <include name="fuegoenterprise-antlib.jar"/>
            <include name="fuegoj2ee-antlib.jar"/>
            <include name="fuego-test-antlib.jar"/>
        </fileset>
    </path>
    <typedef resource="fuego/internal/test/ant/antlib.xml"       
uri="antlib:fuego.internal.test.ant"       
loaderRef="fuego.internal.test" 
classpathref="fuego.internal.test.antlibs.path"/>
    <typedef resource="fuego/tools/ant/enterprise/antlib.xml" 
uri="antlib:fuego.tools.ant.enterprise" loaderRef="fuego.internal.test" 
classpathref="fuego.internal.test.antlibs.path"/>
    <typedef resource="fuego/tools/ant/express/antlib.xml"    
uri="antlib:fuego.tools.ant.express"      
loaderRef="fuego.internal.test" 
classpathref="fuego.internal.test.antlibs.path"/>
    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"          
uri="antlib:fuego.tools.ant.j2ee"          
loaderRef="fuego.internal.test" 
classpathref="fuego.internal.test.antlibs.path"/>
</project>

another Jar "fuegocore.jar" is in the classpath manifest of those jars, 
inside the fuegocore jar there is a clas "Loader".

When I am executing one of the tasks in the antlib I do this.

Inside an Utils.class static method:
        task.log("[LOADERS]  Loader Class [" + Loader.class.hashCode() + 
"/" + Loader.class.getClassLoader() + "]");
        task.log("[LOADERS]  Utils Class [" + Utils.class.hashCode() + 
"/" + Utils.class.getClassLoader() + "]");

and  this is the result I get when I run this multiple times in the same 
ant run.

[t:testsetup] [LOADERS]  Loader Class 
[6597453/java.net.URLClassLoader@affc70]
[t:testsetup] [LOADERS]  Utils Class 
[19551658/org.apache.tools.ant.loader.AntClassLoader2@153f67e]

[t:testsetup] [LOADERS]  Loader Class 
[6597453/java.net.URLClassLoader@affc70]
[t:testsetup] [LOADERS]  Utils Class 
[10520143/org.apache.tools.ant.loader.AntClassLoader2@9a9b65]

[t:testsetup] [LOADERS]  Loader Class 
[6597453/java.net.URLClassLoader@affc70]
[t:testsetup] [LOADERS]  Utils Class 
[28623319/org.apache.tools.ant.loader.AntClassLoader2@da90c]



the thing is: WHY THE LOADER CLASS IS ALWAYS THE SAME WHILE THE UTILS 
CLASS IS ALWAYS IN DIFFERENT ANT CLASSLOADERS!!!

Also, If I put a static {} block in the Loader class it is invoked many 
times, not only one as it should, being the same class the one being 
returned.

Please help,  I cannot understand what is causing this and the 
side-effect is that I get OutOfMemory errors when I run nightly batch tests.


Everything is appreciated.

MAriano

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


Re: antlibs and classloaders #2

Posted by Peter Reilly <pe...@corvil.com>.
This soulds ok, but it could be done
like this:

<onceonly>
    <classpath id="fuego.classpath">
       <fileset dir="${fuego.basedir}/lib">
           <include name="fuegoexpress-antlib.jar"/>
           <include name="fuegoenterprise-antlib.jar"/>
           <include name="fuegoj2ee-antlib.jar"/>
           <include name="fuego-test-antlib.jar"/>
       </fileset>
   </classpath>
   <typedef uri="antlib:fuego.tools.ant.enterprise"
                  classpathref="fuego.classpath"
                  loaderref="fuego.classpath.loader"
                  resource="fuego/tools/ant/j2ee/antlib.xml"/>
   <typedef uri="antlib:fuego.tools.ant.express"
                  loaderref="fuego.classpath.loader"
                  resource="fuego/internal/test/ant/myFile.xml">
</onceonly>

see:
http://marc.theaimsgroup.com/?l=ant-dev&m=108331661709918&w=2

Peter
Mariano Benitez wrote:

> Peter Reilly wrote:
>
>> another thing, I did the <typedef> thing because I cannot add 
>> classpath to an antlib definition, so the problems are chained....
>>
>> I hope to get this in for ant 1.6.2.
>
>
> This is still in a definition process, I guess, so I cannot make any 
> work towards this direction.
>
>> You would still face the problem.
>> The antlib: namespace automatic loading of tasks/types is only 
>> triggered if a task or type from
>> the namespace is used.
>>
> From what you said I understand that the antlib definition is lazy and 
> done from the current ant and descendents, not for the whole ant 
> script, this is why if the usage of an antlib task is inside subants, 
> then for each one another classloader is created. That's why if I 
> define it in the top level ant it applies for all subants.
>
> So, I am thinking of the following workaround for the complete scope 
> of the problem:
>
> I create a task <antlib> that performs would look like this:
>
> <antlib property="fuego.antlib.defined">
>    <classpath>
>        <fileset dir="${fuego.basedir}/lib">
>            <include name="fuegoexpress-antlib.jar"/>
>            <include name="fuegoenterprise-antlib.jar"/>
>            <include name="fuegoj2ee-antlib.jar"/>
>            <include name="fuego-test-antlib.jar"/>
>        </fileset>
>    </classpath>
>    <typedef package="fuego.tools.ant.enterprise"/>
>    <typedef package="fuego.tools.ant.express"/>
>    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"/>
>    <typedef resource="fuego/internal/test/ant/myFile.xml"/>
> </antlib>
>
> Here I would check with the property, and if not set define a 
> classloader with that classpath and define the antlibs in that loader, 
> just what I do in the import file, but inside a task. I can put this 
> task in the ant -lib path, and use it in the import files.
>
>
> What do you think?
>
> MAriano
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>


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


Re: antlibs and classloaders #2

Posted by Mariano Benitez <ma...@fuegolabs.com>.
Peter Reilly wrote:

> another thing, I did the <typedef> thing because I cannot add 
> classpath to an antlib definition, so the problems are chained....
>
> I hope to get this in for ant 1.6.2.

This is still in a definition process, I guess, so I cannot make any 
work towards this direction.

> You would still face the problem.
> The antlib: namespace automatic loading of tasks/types is only 
> triggered if a task or type from
> the namespace is used.
>
 From what you said I understand that the antlib definition is lazy and 
done from the current ant and descendents, not for the whole ant script, 
this is why if the usage of an antlib task is inside subants, then for 
each one another classloader is created. That's why if I define it in 
the top level ant it applies for all subants.

So, I am thinking of the following workaround for the complete scope of 
the problem:

I create a task <antlib> that performs would look like this:

<antlib property="fuego.antlib.defined">
    <classpath>
        <fileset dir="${fuego.basedir}/lib">
            <include name="fuegoexpress-antlib.jar"/>
            <include name="fuegoenterprise-antlib.jar"/>
            <include name="fuegoj2ee-antlib.jar"/>
            <include name="fuego-test-antlib.jar"/>
        </fileset>
    </classpath>
    <typedef package="fuego.tools.ant.enterprise"/>
    <typedef package="fuego.tools.ant.express"/>
    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"/>
    <typedef resource="fuego/internal/test/ant/myFile.xml"/>
</antlib>

Here I would check with the property, and if not set define a 
classloader with that classpath and define the antlibs in that loader, 
just what I do in the import file, but inside a task. I can put this 
task in the ant -lib path, and use it in the import files.


What do you think?

MAriano




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


Re: antlibs and classloaders #2

Posted by Peter Reilly <pe...@corvil.com>.
Mariano Benitez wrote:

> another thing, I did the <typedef> thing because I cannot add 
> classpath to an antlib definition, so the problems are chained....

I hope to get this in for ant 1.6.2.

>
> If I would define antlibs with classpath references directly it would 
> be better....

You would still face the problem.
The antlib: namespace automatic loading of tasks/types is only triggered 
if a task or type from
the namespace is used.

for example if you have a master.xml file:

<project name="master" default="dosubprojects">
   <target name="dosubprojects">
      <subant target="">
         <fileset dir="." includes="**/build.xml"/>
      </subant>
   </target>
</project>

and each of the projects had:
<project xmlns:cpp="antlib:net.sf.antcontrib.cpptasks" default="compile">
  <cpp:compiler id="compiler.flags">
   ...
</project>

Each of the subprojects would trigger the task defs for the cpptasks namespace.

The way to work around this would be to do:
<project name="master" default="dosubprojects" xmlns:cpp="antlib:net.sf.antcontrib.cpptasks">
   <cpp:compiler id="dummy.flags"/>
   <target name="dosubprojects">
      <subant target="">
         <fileset dir="." includes="**/build.xml"/>
      </subant>
   </target>
</project>

Peter



>
> MAriano
>
> Mariano Benitez wrote:
>
>> but ... If I call "typedef" for the same file, with the same task, 
>> same uri, etc, why it redefine the tasks if they are already defined?
>>
>> BTW, it could help an "unless" attribute for typedef, not to do it 
>> again :)
>>   <typedef resource="fuego/internal/test/ant/antlib.xml"       
>> uri="antlib:fuego.internal.test.ant"       
>> loaderRef="fuego.internal.test" 
>> classpathref="fuego.internal.test.antlibs.path" unless="defined"/>
>>   <property name="defined" value="true"/>
>>
>> MAriano
>>
>> Peter Reilly wrote:
>>
>>> Hi Mariano,
>>> I assume you are calling the "typedef" commands multiple times.
>>> - hence the different antloaders. But you only need to typedef
>>> the types/tasks once.
>>>
>>> You should wrap the taskdefs in a macrodef or a target,
>>> and call them once in the master build file before doing
>>> any subant, or ant calls.
>>>
>>> Peter
>>>
>>> Mariano Benitez wrote:
>>>
>>>> I am at the edge of a mental crisis, I need help....
>>>>
>>>>
>>>> Can someone explain how antlib paths and tasks works, I have this 
>>>> situation that I cannot understand.
>>>>
>>>>
>>>> I defined this:
>>>>
>>>> <project name="fuego.internal.test.include" basedir=".">
>>>>
>>>>    <property name="xml.encoding" value="ISO-8859-1"/>
>>>>      <path id="fuego.internal.test.antlibs.path">
>>>>        <fileset dir="${fuego.basedir}/lib">
>>>>            <include name="fuegoexpress-antlib.jar"/>
>>>>            <include name="fuegoenterprise-antlib.jar"/>
>>>>            <include name="fuegoj2ee-antlib.jar"/>
>>>>            <include name="fuego-test-antlib.jar"/>
>>>>        </fileset>
>>>>    </path>
>>>>    <typedef resource="fuego/internal/test/ant/antlib.xml"       
>>>> uri="antlib:fuego.internal.test.ant"       
>>>> loaderRef="fuego.internal.test" 
>>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>>    <typedef resource="fuego/tools/ant/enterprise/antlib.xml" 
>>>> uri="antlib:fuego.tools.ant.enterprise" 
>>>> loaderRef="fuego.internal.test" 
>>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>>    <typedef resource="fuego/tools/ant/express/antlib.xml"    
>>>> uri="antlib:fuego.tools.ant.express"      
>>>> loaderRef="fuego.internal.test" 
>>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>>    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"          
>>>> uri="antlib:fuego.tools.ant.j2ee"          
>>>> loaderRef="fuego.internal.test" 
>>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>> </project>
>>>>
>>>> another Jar "fuegocore.jar" is in the classpath manifest of those 
>>>> jars, inside the fuegocore jar there is a clas "Loader".
>>>>
>>>> When I am executing one of the tasks in the antlib I do this.
>>>>
>>>> Inside an Utils.class static method:
>>>>        task.log("[LOADERS]  Loader Class [" + 
>>>> Loader.class.hashCode() + "/" + Loader.class.getClassLoader() + "]");
>>>>        task.log("[LOADERS]  Utils Class [" + Utils.class.hashCode() 
>>>> + "/" + Utils.class.getClassLoader() + "]");
>>>>
>>>> and  this is the result I get when I run this multiple times in the 
>>>> same ant run.
>>>>
>>>> [t:testsetup] [LOADERS]  Loader Class 
>>>> [6597453/java.net.URLClassLoader@affc70]
>>>> [t:testsetup] [LOADERS]  Utils Class 
>>>> [19551658/org.apache.tools.ant.loader.AntClassLoader2@153f67e]
>>>>
>>>> [t:testsetup] [LOADERS]  Loader Class 
>>>> [6597453/java.net.URLClassLoader@affc70]
>>>> [t:testsetup] [LOADERS]  Utils Class 
>>>> [10520143/org.apache.tools.ant.loader.AntClassLoader2@9a9b65]
>>>>
>>>> [t:testsetup] [LOADERS]  Loader Class 
>>>> [6597453/java.net.URLClassLoader@affc70]
>>>> [t:testsetup] [LOADERS]  Utils Class 
>>>> [28623319/org.apache.tools.ant.loader.AntClassLoader2@da90c]
>>>>
>>>>
>>>>
>>>> the thing is: WHY THE LOADER CLASS IS ALWAYS THE SAME WHILE THE 
>>>> UTILS CLASS IS ALWAYS IN DIFFERENT ANT CLASSLOADERS!!!
>>>>
>>>> Also, If I put a static {} block in the Loader class it is invoked 
>>>> many times, not only one as it should, being the same class the one 
>>>> being returned.
>>>>
>>>> Please help,  I cannot understand what is causing this and the 
>>>> side-effect is that I get OutOfMemory errors when I run nightly 
>>>> batch tests.
>>>>
>>>>
>>>> Everything is appreciated.
>>>>
>>>> MAriano
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>>> For additional commands, e-mail: dev-help@ant.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: dev-help@ant.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>


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


Re: antlibs and classloaders #2

Posted by Mariano Benitez <ma...@fuegolabs.com>.
another thing, I did the <typedef> thing because I cannot add classpath 
to an antlib definition, so the problems are chained....

If I would define antlibs with classpath references directly it would be 
better....

MAriano

Mariano Benitez wrote:

> but ... If I call "typedef" for the same file, with the same task, 
> same uri, etc, why it redefine the tasks if they are already defined?
>
> BTW, it could help an "unless" attribute for typedef, not to do it 
> again :)
>   <typedef resource="fuego/internal/test/ant/antlib.xml"       
> uri="antlib:fuego.internal.test.ant"       
> loaderRef="fuego.internal.test" 
> classpathref="fuego.internal.test.antlibs.path" unless="defined"/>
>   <property name="defined" value="true"/>
>
> MAriano
>
> Peter Reilly wrote:
>
>> Hi Mariano,
>> I assume you are calling the "typedef" commands multiple times.
>> - hence the different antloaders. But you only need to typedef
>> the types/tasks once.
>>
>> You should wrap the taskdefs in a macrodef or a target,
>> and call them once in the master build file before doing
>> any subant, or ant calls.
>>
>> Peter
>>
>> Mariano Benitez wrote:
>>
>>> I am at the edge of a mental crisis, I need help....
>>>
>>>
>>> Can someone explain how antlib paths and tasks works, I have this 
>>> situation that I cannot understand.
>>>
>>>
>>> I defined this:
>>>
>>> <project name="fuego.internal.test.include" basedir=".">
>>>
>>>    <property name="xml.encoding" value="ISO-8859-1"/>
>>>      <path id="fuego.internal.test.antlibs.path">
>>>        <fileset dir="${fuego.basedir}/lib">
>>>            <include name="fuegoexpress-antlib.jar"/>
>>>            <include name="fuegoenterprise-antlib.jar"/>
>>>            <include name="fuegoj2ee-antlib.jar"/>
>>>            <include name="fuego-test-antlib.jar"/>
>>>        </fileset>
>>>    </path>
>>>    <typedef resource="fuego/internal/test/ant/antlib.xml"       
>>> uri="antlib:fuego.internal.test.ant"       
>>> loaderRef="fuego.internal.test" 
>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>    <typedef resource="fuego/tools/ant/enterprise/antlib.xml" 
>>> uri="antlib:fuego.tools.ant.enterprise" 
>>> loaderRef="fuego.internal.test" 
>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>    <typedef resource="fuego/tools/ant/express/antlib.xml"    
>>> uri="antlib:fuego.tools.ant.express"      
>>> loaderRef="fuego.internal.test" 
>>> classpathref="fuego.internal.test.antlibs.path"/>
>>>    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"          
>>> uri="antlib:fuego.tools.ant.j2ee"          
>>> loaderRef="fuego.internal.test" 
>>> classpathref="fuego.internal.test.antlibs.path"/>
>>> </project>
>>>
>>> another Jar "fuegocore.jar" is in the classpath manifest of those 
>>> jars, inside the fuegocore jar there is a clas "Loader".
>>>
>>> When I am executing one of the tasks in the antlib I do this.
>>>
>>> Inside an Utils.class static method:
>>>        task.log("[LOADERS]  Loader Class [" + 
>>> Loader.class.hashCode() + "/" + Loader.class.getClassLoader() + "]");
>>>        task.log("[LOADERS]  Utils Class [" + Utils.class.hashCode() 
>>> + "/" + Utils.class.getClassLoader() + "]");
>>>
>>> and  this is the result I get when I run this multiple times in the 
>>> same ant run.
>>>
>>> [t:testsetup] [LOADERS]  Loader Class 
>>> [6597453/java.net.URLClassLoader@affc70]
>>> [t:testsetup] [LOADERS]  Utils Class 
>>> [19551658/org.apache.tools.ant.loader.AntClassLoader2@153f67e]
>>>
>>> [t:testsetup] [LOADERS]  Loader Class 
>>> [6597453/java.net.URLClassLoader@affc70]
>>> [t:testsetup] [LOADERS]  Utils Class 
>>> [10520143/org.apache.tools.ant.loader.AntClassLoader2@9a9b65]
>>>
>>> [t:testsetup] [LOADERS]  Loader Class 
>>> [6597453/java.net.URLClassLoader@affc70]
>>> [t:testsetup] [LOADERS]  Utils Class 
>>> [28623319/org.apache.tools.ant.loader.AntClassLoader2@da90c]
>>>
>>>
>>>
>>> the thing is: WHY THE LOADER CLASS IS ALWAYS THE SAME WHILE THE 
>>> UTILS CLASS IS ALWAYS IN DIFFERENT ANT CLASSLOADERS!!!
>>>
>>> Also, If I put a static {} block in the Loader class it is invoked 
>>> many times, not only one as it should, being the same class the one 
>>> being returned.
>>>
>>> Please help,  I cannot understand what is causing this and the 
>>> side-effect is that I get OutOfMemory errors when I run nightly 
>>> batch tests.
>>>
>>>
>>> Everything is appreciated.
>>>
>>> MAriano
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: dev-help@ant.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>

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


Re: antlibs and classloaders #2

Posted by Mariano Benitez <ma...@fuegolabs.com>.
but ... If I call "typedef" for the same file, with the same task, same 
uri, etc, why it redefine the tasks if they are already defined?

BTW, it could help an "unless" attribute for typedef, not to do it again :)
   <typedef resource="fuego/internal/test/ant/antlib.xml"       
uri="antlib:fuego.internal.test.ant"       
loaderRef="fuego.internal.test" 
classpathref="fuego.internal.test.antlibs.path" unless="defined"/>
   <property name="defined" value="true"/>

MAriano

Peter Reilly wrote:

> Hi Mariano,
> I assume you are calling the "typedef" commands multiple times.
> - hence the different antloaders. But you only need to typedef
> the types/tasks once.
>
> You should wrap the taskdefs in a macrodef or a target,
> and call them once in the master build file before doing
> any subant, or ant calls.
>
> Peter
>
> Mariano Benitez wrote:
>
>> I am at the edge of a mental crisis, I need help....
>>
>>
>> Can someone explain how antlib paths and tasks works, I have this 
>> situation that I cannot understand.
>>
>>
>> I defined this:
>>
>> <project name="fuego.internal.test.include" basedir=".">
>>
>>    <property name="xml.encoding" value="ISO-8859-1"/>
>>      <path id="fuego.internal.test.antlibs.path">
>>        <fileset dir="${fuego.basedir}/lib">
>>            <include name="fuegoexpress-antlib.jar"/>
>>            <include name="fuegoenterprise-antlib.jar"/>
>>            <include name="fuegoj2ee-antlib.jar"/>
>>            <include name="fuego-test-antlib.jar"/>
>>        </fileset>
>>    </path>
>>    <typedef resource="fuego/internal/test/ant/antlib.xml"       
>> uri="antlib:fuego.internal.test.ant"       
>> loaderRef="fuego.internal.test" 
>> classpathref="fuego.internal.test.antlibs.path"/>
>>    <typedef resource="fuego/tools/ant/enterprise/antlib.xml" 
>> uri="antlib:fuego.tools.ant.enterprise" 
>> loaderRef="fuego.internal.test" 
>> classpathref="fuego.internal.test.antlibs.path"/>
>>    <typedef resource="fuego/tools/ant/express/antlib.xml"    
>> uri="antlib:fuego.tools.ant.express"      
>> loaderRef="fuego.internal.test" 
>> classpathref="fuego.internal.test.antlibs.path"/>
>>    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"          
>> uri="antlib:fuego.tools.ant.j2ee"          
>> loaderRef="fuego.internal.test" 
>> classpathref="fuego.internal.test.antlibs.path"/>
>> </project>
>>
>> another Jar "fuegocore.jar" is in the classpath manifest of those 
>> jars, inside the fuegocore jar there is a clas "Loader".
>>
>> When I am executing one of the tasks in the antlib I do this.
>>
>> Inside an Utils.class static method:
>>        task.log("[LOADERS]  Loader Class [" + Loader.class.hashCode() 
>> + "/" + Loader.class.getClassLoader() + "]");
>>        task.log("[LOADERS]  Utils Class [" + Utils.class.hashCode() + 
>> "/" + Utils.class.getClassLoader() + "]");
>>
>> and  this is the result I get when I run this multiple times in the 
>> same ant run.
>>
>> [t:testsetup] [LOADERS]  Loader Class 
>> [6597453/java.net.URLClassLoader@affc70]
>> [t:testsetup] [LOADERS]  Utils Class 
>> [19551658/org.apache.tools.ant.loader.AntClassLoader2@153f67e]
>>
>> [t:testsetup] [LOADERS]  Loader Class 
>> [6597453/java.net.URLClassLoader@affc70]
>> [t:testsetup] [LOADERS]  Utils Class 
>> [10520143/org.apache.tools.ant.loader.AntClassLoader2@9a9b65]
>>
>> [t:testsetup] [LOADERS]  Loader Class 
>> [6597453/java.net.URLClassLoader@affc70]
>> [t:testsetup] [LOADERS]  Utils Class 
>> [28623319/org.apache.tools.ant.loader.AntClassLoader2@da90c]
>>
>>
>>
>> the thing is: WHY THE LOADER CLASS IS ALWAYS THE SAME WHILE THE UTILS 
>> CLASS IS ALWAYS IN DIFFERENT ANT CLASSLOADERS!!!
>>
>> Also, If I put a static {} block in the Loader class it is invoked 
>> many times, not only one as it should, being the same class the one 
>> being returned.
>>
>> Please help,  I cannot understand what is causing this and the 
>> side-effect is that I get OutOfMemory errors when I run nightly batch 
>> tests.
>>
>>
>> Everything is appreciated.
>>
>> MAriano
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>> For additional commands, e-mail: dev-help@ant.apache.org
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>

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


Re: antlibs and classloaders #2

Posted by Peter Reilly <pe...@corvil.com>.
Hi Mariano,
I assume you are calling the "typedef" commands multiple times.
- hence the different antloaders. But you only need to typedef
the types/tasks once.

You should wrap the taskdefs in a macrodef or a target,
and call them once in the master build file before doing
any subant, or ant calls.

Peter

Mariano Benitez wrote:

> I am at the edge of a mental crisis, I need help....
>
>
> Can someone explain how antlib paths and tasks works, I have this 
> situation that I cannot understand.
>
>
> I defined this:
>
> <project name="fuego.internal.test.include" basedir=".">
>
>    <property name="xml.encoding" value="ISO-8859-1"/>
>      <path id="fuego.internal.test.antlibs.path">
>        <fileset dir="${fuego.basedir}/lib">
>            <include name="fuegoexpress-antlib.jar"/>
>            <include name="fuegoenterprise-antlib.jar"/>
>            <include name="fuegoj2ee-antlib.jar"/>
>            <include name="fuego-test-antlib.jar"/>
>        </fileset>
>    </path>
>    <typedef resource="fuego/internal/test/ant/antlib.xml"       
> uri="antlib:fuego.internal.test.ant"       
> loaderRef="fuego.internal.test" 
> classpathref="fuego.internal.test.antlibs.path"/>
>    <typedef resource="fuego/tools/ant/enterprise/antlib.xml" 
> uri="antlib:fuego.tools.ant.enterprise" 
> loaderRef="fuego.internal.test" 
> classpathref="fuego.internal.test.antlibs.path"/>
>    <typedef resource="fuego/tools/ant/express/antlib.xml"    
> uri="antlib:fuego.tools.ant.express"      
> loaderRef="fuego.internal.test" 
> classpathref="fuego.internal.test.antlibs.path"/>
>    <typedef resource="fuego/tools/ant/j2ee/antlib.xml"          
> uri="antlib:fuego.tools.ant.j2ee"          
> loaderRef="fuego.internal.test" 
> classpathref="fuego.internal.test.antlibs.path"/>
> </project>
>
> another Jar "fuegocore.jar" is in the classpath manifest of those 
> jars, inside the fuegocore jar there is a clas "Loader".
>
> When I am executing one of the tasks in the antlib I do this.
>
> Inside an Utils.class static method:
>        task.log("[LOADERS]  Loader Class [" + Loader.class.hashCode() 
> + "/" + Loader.class.getClassLoader() + "]");
>        task.log("[LOADERS]  Utils Class [" + Utils.class.hashCode() + 
> "/" + Utils.class.getClassLoader() + "]");
>
> and  this is the result I get when I run this multiple times in the 
> same ant run.
>
> [t:testsetup] [LOADERS]  Loader Class 
> [6597453/java.net.URLClassLoader@affc70]
> [t:testsetup] [LOADERS]  Utils Class 
> [19551658/org.apache.tools.ant.loader.AntClassLoader2@153f67e]
>
> [t:testsetup] [LOADERS]  Loader Class 
> [6597453/java.net.URLClassLoader@affc70]
> [t:testsetup] [LOADERS]  Utils Class 
> [10520143/org.apache.tools.ant.loader.AntClassLoader2@9a9b65]
>
> [t:testsetup] [LOADERS]  Loader Class 
> [6597453/java.net.URLClassLoader@affc70]
> [t:testsetup] [LOADERS]  Utils Class 
> [28623319/org.apache.tools.ant.loader.AntClassLoader2@da90c]
>
>
>
> the thing is: WHY THE LOADER CLASS IS ALWAYS THE SAME WHILE THE UTILS 
> CLASS IS ALWAYS IN DIFFERENT ANT CLASSLOADERS!!!
>
> Also, If I put a static {} block in the Loader class it is invoked 
> many times, not only one as it should, being the same class the one 
> being returned.
>
> Please help,  I cannot understand what is causing this and the 
> side-effect is that I get OutOfMemory errors when I run nightly batch 
> tests.
>
>
> Everything is appreciated.
>
> MAriano
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>
>


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