Class cast exception with executor - class loading issue

View: New views
5 Messages — Rating Filter:   Alert me  

Class cast exception with executor - class loading issue

by Raja Nagendra Kumar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Class cast exception with executor - class loading issue

by Stefan Bodewig :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 2009-11-06, Raja Nagendra Kumar <Nagendra.Raja@...> 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@...
For additional commands, e-mail: user-help@...


Re: Class cast exception with executor - class loading issue

by Raja Nagendra Kumar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Class cast exception with executor - class loading issue

by antoinell :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 <Nagendra.Raja@...>
> An: user@...
> 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@...
> For additional commands, e-mail: user-help@...

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


Re: Class cast exception with executor - class loading issue

by Raja Nagendra Kumar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you both.

Both your solutions are working.

Regards,
Nagendra