You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Raja Nagendra Kumar <Na...@tejasoft.com> on 2009/11/06 12:51:51 UTC

Class cast exception with executor - class loading issue

Hi,

When using the custom executor with taskdef's loaded from project classpath,
I see class cast exception when trying to fetch the executor from project
and casting it to custom class.

java.lang.ClassCastException:
com.tejasoft.ant.utils.executor.TejaMobileExecutor cannot
 be cast to com.tejasoft.ant.utils.executor.TejaMobileExecutor

I read from forums that it is when casting is happening like this

Executor ex = getProject();
	return ((TejaMobileExecutor) ex).getDeviceBuilder();

The class in casting (TejaMobileExecutor) may be getting loaded from a
different classloader than the class which was created in  parents builds
Executor class

 public Executor getSubProjectExecutor()
    {
	return new TejaMobileExecutor();
	//return this;
    }

How to resolve such issue as getSubProjectExecutor() should use parent
builds class loader wher as casting to be done in subproject.

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
-- 
View this message in context: http://old.nabble.com/Class-cast-exception-with-executor---class-loading-issue-tp26230483p26230483.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Class cast exception with executor - class loading issue

Posted by Raja Nagendra Kumar <Na...@tejasoft.com>.
Thank you both. 

Both your solutions are working. 

Regards,
Nagendra


-- 
View this message in context: http://old.nabble.com/Class-cast-exception-with-executor---class-loading-issue-tp26230483p26268142.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Class cast exception with executor - class loading issue

Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Raja,

I am not sure whether this can help you. I am using the classloader task included in the project http://sourceforge.net/projects/enitsys/files/JTools/

I use it with this snippet 
    <classloadertask classpathRef="all.https.cp" loader="thread"/>

where all.https.cp is the id of a path defined before in my build file.

I had to do this mainly to use the SSL layer of IBM WebSphere 6.1.

Regards,

Antoine

-------- Original-Nachricht --------
> Datum: Fri, 6 Nov 2009 07:59:07 -0800 (PST)
> Von: Raja Nagendra Kumar <Na...@tejasoft.com>
> An: user@ant.apache.org
> Betreff: Re: Class cast exception with executor - class loading issue

> 
> A Project created using class Ant is having the executor which is loaded
> by
> parent project class loader. Hence casting of classloader to the same
> class
> is creating a issue due to different class loaders.
> 
> How does one can resolve such issues.. as from the custom classloader, we
> want to store some data and retrieve it.
> 
> Regards,
> Nagendra
> -- 
> View this message in context:
> http://old.nabble.com/Class-cast-exception-with-executor---class-loading-issue-tp26230483p26230813.html
> Sent from the Ant - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org

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


Re: Class cast exception with executor - class loading issue

Posted by Raja Nagendra Kumar <Na...@tejasoft.com>.
A Project created using class Ant is having the executor which is loaded by
parent project class loader. Hence casting of classloader to the same class
is creating a issue due to different class loaders.

How does one can resolve such issues.. as from the custom classloader, we
want to store some data and retrieve it.

Regards,
Nagendra
-- 
View this message in context: http://old.nabble.com/Class-cast-exception-with-executor---class-loading-issue-tp26230483p26230813.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


Re: Class cast exception with executor - class loading issue

Posted by Stefan Bodewig <bo...@apache.org>.
On 2009-11-06, Raja Nagendra Kumar <Na...@tejasoft.com> wrote:

> I read from forums that it is when casting is happening like this

> Executor ex = getProject();
> 	return ((TejaMobileExecutor) ex).getDeviceBuilder();

> The class in casting (TejaMobileExecutor) may be getting loaded from a
> different classloader than the class which was created in  parents builds
> Executor class

Yes.  You must ensure all your classes are loaded using the same
classloader.  You can achieve that by using loaderref on typedef/taskdef
and using the same id everywhere.  loaderref creates a project reference
holding your classloader.

With inheritrefs set to true on your ant task - or explicit nested
reference elements of said ant task - the classloader should get
transfered from the parent to the child project.

Stefan

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