Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Yet Another ClassLoader Question
Yet Another ClassLoader Question [message #464899] Mon, 19 March 2007 16:42 Go to next message
Eclipse UserFriend
Originally posted by: Andreas.Fluegge.burningbush.de

Hallo,

Sorry to ask this question for the 1.000.000 (or so) time. I have
browsed through a couple of postings but now I am more irritated than
enlightened. Here is the my problem:

I have a plugin that allows users to create helper classes my plugin can
use for decoding data it reads in. If the user does not provide such a
helper class than the data is displayed as raw bytes otherwise the
helper class is used to decode the data for display. The user adds
these helper classes by editing a property file that tells me the name
and location of the helper class (That's the plan so far...). What I am
trying to achieve is to add the paths to these helper class to a
classloader. I tried the naive approach of using URLClassLoader, load
the class that might reference these user provided classes with this
URLClassLoader in the hope that this URLClassLoader will become the
current classloader for the loaded class. Well... does not work. Is
there a way of doing this kind of magic and is there some sample code
demonstrating it for an intellectually impaired person like me?

Thanks,
Andreas
Re: Yet Another ClassLoader Question [message #464900 is a reply to message #464899] Mon, 19 March 2007 17:10 Go to previous messageGo to next message
Charlie Kelly is currently offline Charlie KellyFriend
Messages: 276
Registered: July 2009
Senior Member
Hi Andreas,

See my post this morning to this list in response to "eclipse plugin
classpath and JDBC access". I think that this will answer your question.

Charlie



Andreas Fluegge wrote:
> Hallo,
>
> Sorry to ask this question for the 1.000.000 (or so) time. I have
> browsed through a couple of postings but now I am more irritated than
> enlightened. Here is the my problem:
>
> I have a plugin that allows users to create helper classes my plugin can
> use for decoding data it reads in. If the user does not provide such a
> helper class than the data is displayed as raw bytes otherwise the
> helper class is used to decode the data for display. The user adds
> these helper classes by editing a property file that tells me the name
> and location of the helper class (That's the plan so far...). What I am
> trying to achieve is to add the paths to these helper class to a
> classloader. I tried the naive approach of using URLClassLoader, load
> the class that might reference these user provided classes with this
> URLClassLoader in the hope that this URLClassLoader will become the
> current classloader for the loaded class. Well... does not work. Is
> there a way of doing this kind of magic and is there some sample code
> demonstrating it for an intellectually impaired person like me?
>
> Thanks,
> Andreas
Re: Yet Another ClassLoader Question [message #464902 is a reply to message #464900] Mon, 19 March 2007 18:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Andreas.Fluegge.burningbush.de

Charlie,

thanks for your reply. I just read the mentioned chapter. The problem
with this approach is still kind of static. In my plugin I open a
dialog to setup classes/jars which then are stored as properties and
when it comes that I need to reference these classes I (would like to)
add them to 'the classpath' used by just that class that has to work
with them. Any ideas how to get that to work?

Andreas


Charlie Kelly schrieb:
> Hi Andreas,
>
> See my post this morning to this list in response to "eclipse plugin
> classpath and JDBC access". I think that this will answer your question.
>
> Charlie
>
>
>
> Andreas Fluegge wrote:
>> Hallo,
>>
>> Sorry to ask this question for the 1.000.000 (or so) time. I have
>> browsed through a couple of postings but now I am more irritated than
>> enlightened. Here is the my problem:
>>
>> I have a plugin that allows users to create helper classes my plugin
>> can use for decoding data it reads in. If the user does not provide
>> such a helper class than the data is displayed as raw bytes otherwise
>> the helper class is used to decode the data for display. The user
>> adds these helper classes by editing a property file that tells me the
>> name and location of the helper class (That's the plan so far...).
>> What I am trying to achieve is to add the paths to these helper class
>> to a classloader. I tried the naive approach of using URLClassLoader,
>> load the class that might reference these user provided classes with
>> this URLClassLoader in the hope that this URLClassLoader will become
>> the current classloader for the loaded class. Well... does not work.
>> Is there a way of doing this kind of magic and is there some sample
>> code demonstrating it for an intellectually impaired person like me?
>>
>> Thanks,
>> Andreas
Re: Yet Another ClassLoader Question [message #464903 is a reply to message #464902] Mon, 19 March 2007 18:53 Go to previous messageGo to next message
Charlie Kelly is currently offline Charlie KellyFriend
Messages: 276
Registered: July 2009
Senior Member
Hi Andreas,

Short answer: no I don't know how to do that.
I've concentrated upon designing POJOs that are available within a J2EE
container (JBoss), available within an Eclipse RCP, and available to
Hibernate within the RCP. Since each "container" has different
requirements, I've been conservative with design.

Longer answer: you'll need to understand the interaction between osgi
and Eclipse plugins to implement dynamic class discovery from stored
properties. It seems like osgi is developing in a different direction:
to become a generic platform for servers, where classes are know when
the server is started.

Charlie

Andreas Fluegge wrote:
> Charlie,
>
> thanks for your reply. I just read the mentioned chapter. The problem
> with this approach is still kind of static. In my plugin I open a
> dialog to setup classes/jars which then are stored as properties and
> when it comes that I need to reference these classes I (would like to)
> add them to 'the classpath' used by just that class that has to work
> with them. Any ideas how to get that to work?
>
> Andreas
>
>
> Charlie Kelly schrieb:
>> Hi Andreas,
>>
>> See my post this morning to this list in response to "eclipse plugin
>> classpath and JDBC access". I think that this will answer your question.
>>
>> Charlie
>>
>>
>>
>> Andreas Fluegge wrote:
>>> Hallo,
>>>
>>> Sorry to ask this question for the 1.000.000 (or so) time. I have
>>> browsed through a couple of postings but now I am more irritated than
>>> enlightened. Here is the my problem:
>>>
>>> I have a plugin that allows users to create helper classes my plugin
>>> can use for decoding data it reads in. If the user does not provide
>>> such a helper class than the data is displayed as raw bytes otherwise
>>> the helper class is used to decode the data for display. The user
>>> adds these helper classes by editing a property file that tells me
>>> the name and location of the helper class (That's the plan so
>>> far...). What I am trying to achieve is to add the paths to these
>>> helper class to a classloader. I tried the naive approach of using
>>> URLClassLoader, load the class that might reference these user
>>> provided classes with this URLClassLoader in the hope that this
>>> URLClassLoader will become the current classloader for the loaded
>>> class. Well... does not work. Is there a way of doing this kind of
>>> magic and is there some sample code demonstrating it for an
>>> intellectually impaired person like me?
>>>
>>> Thanks,
>>> Andreas
Re: Yet Another ClassLoader Question [message #464921 is a reply to message #464899] Tue, 20 March 2007 14:44 Go to previous messageGo to next message
Andrew Niefer is currently offline Andrew NieferFriend
Messages: 990
Registered: July 2009
Senior Member
Andreas,
This is exactly what extension points and extensions are for. Everything is
specified in the plugin.xml and the extension registry take care of loading the
classes for you. I don't have any reference links handy, but I'm sure google
can find everything you need.

-Andrew

Andreas Fluegge wrote:
> Hallo,
>
> Sorry to ask this question for the 1.000.000 (or so) time. I have
> browsed through a couple of postings but now I am more irritated than
> enlightened. Here is the my problem:
>
> I have a plugin that allows users to create helper classes my plugin can
> use for decoding data it reads in. If the user does not provide such a
> helper class than the data is displayed as raw bytes otherwise the
> helper class is used to decode the data for display. The user adds
> these helper classes by editing a property file that tells me the name
> and location of the helper class (That's the plan so far...). What I am
> trying to achieve is to add the paths to these helper class to a
> classloader. I tried the naive approach of using URLClassLoader, load
> the class that might reference these user provided classes with this
> URLClassLoader in the hope that this URLClassLoader will become the
> current classloader for the loaded class. Well... does not work. Is
> there a way of doing this kind of magic and is there some sample code
> demonstrating it for an intellectually impaired person like me?
>
> Thanks,
> Andreas
Re: Yet Another ClassLoader Question [message #464932 is a reply to message #464899] Tue, 20 March 2007 20:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Mon, 19 Mar 2007 17:42:47 +0100, Andreas Fluegge wrote:

> Hallo,
>
> Sorry to ask this question for the 1.000.000 (or so) time. I have
> browsed through a couple of postings but now I am more irritated than
> enlightened. Here is the my problem:
>
> I have a plugin that allows users to create helper classes my plugin can
> use for decoding data it reads in. If the user does not provide such a
> helper class than the data is displayed as raw bytes otherwise the
> helper class is used to decode the data for display. The user adds
> these helper classes by editing a property file that tells me the name
> and location of the helper class (That's the plan so far...). What I am
> trying to achieve is to add the paths to these helper class to a
> classloader. I tried the naive approach of using URLClassLoader, load
> the class that might reference these user provided classes with this
> URLClassLoader in the hope that this URLClassLoader will become the
> current classloader for the loaded class. Well... does not work. Is
> there a way of doing this kind of magic and is there some sample code
> demonstrating it for an intellectually impaired person like me?
>
> Thanks,
> Andreas

I fail to see why a simple URLClassloader will not work for you. What
problem are you getting? I have done this time and time again with a
URLclassloader. Its not that hard.

Of course I dont know why you want to use a URLClassloader to load the
class that needs to load the custom class. That dont make sense.
Re: Yet Another ClassLoader Question [message #465176 is a reply to message #464932] Sat, 24 March 2007 21:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Andreas.Fluegge.burningbush.de

Ok, here is more precisely what I want to do: I build a JMS browser. My
problem are ObjectMessages. To be able to render ObjectMessages I need
the class for the object contained in the message. Of course I don't
know what this might be at compile time. So I need to provide a dialog
where users can add the pathes to the classes for their ObjectMessage
types. In the renderer component I need these classes in my classpath
otherwise I get a ClassNotFoundException when I call
message.getObject(). I tried URLClassLoader but it does not work. Maybe
I am plain stupid but I do not see how to get that to work. I always end
up in the DefaultClassLoader context.


CL 'dnoyeB' Gilbert schrieb:
> On Mon, 19 Mar 2007 17:42:47 +0100, Andreas Fluegge wrote:
>
>> Hallo,
>>
>> Sorry to ask this question for the 1.000.000 (or so) time. I have
>> browsed through a couple of postings but now I am more irritated than
>> enlightened. Here is the my problem:
>>
>> I have a plugin that allows users to create helper classes my plugin can
>> use for decoding data it reads in. If the user does not provide such a
>> helper class than the data is displayed as raw bytes otherwise the
>> helper class is used to decode the data for display. The user adds
>> these helper classes by editing a property file that tells me the name
>> and location of the helper class (That's the plan so far...). What I am
>> trying to achieve is to add the paths to these helper class to a
>> classloader. I tried the naive approach of using URLClassLoader, load
>> the class that might reference these user provided classes with this
>> URLClassLoader in the hope that this URLClassLoader will become the
>> current classloader for the loaded class. Well... does not work. Is
>> there a way of doing this kind of magic and is there some sample code
>> demonstrating it for an intellectually impaired person like me?
>>
>> Thanks,
>> Andreas
>
> I fail to see why a simple URLClassloader will not work for you. What
> problem are you getting? I have done this time and time again with a
> URLclassloader. Its not that hard.
>
> Of course I dont know why you want to use a URLClassloader to load the
> class that needs to load the custom class. That dont make sense.
Re: Yet Another ClassLoader Question [message #465185 is a reply to message #465176] Sun, 25 March 2007 19:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Sat, 24 Mar 2007 22:12:04 +0100, Andreas Fluegge wrote:

> Ok, here is more precisely what I want to do: I build a JMS browser. My
> problem are ObjectMessages. To be able to render ObjectMessages I need
> the class for the object contained in the message. Of course I don't
> know what this might be at compile time. So I need to provide a dialog
> where users can add the pathes to the classes for their ObjectMessage
> types. In the renderer component I need these classes in my classpath
> otherwise I get a ClassNotFoundException when I call
> message.getObject(). I tried URLClassLoader but it does not work. Maybe
> I am plain stupid but I do not see how to get that to work. I always end
> up in the DefaultClassLoader context.
>
>

It does not seem as if you are even using the URLClassloader. Your code
must change. Can you show how you are using the URL classloadeR? it does
not automatically append your classpath. you must call it explicitly with
stuff like ClassForName.
Re: Yet Another ClassLoader Question [message #465238 is a reply to message #465176] Mon, 26 March 2007 15:29 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Andreas Fluegge wrote:
> Ok, here is more precisely what I want to do: I build a JMS browser. My
> problem are ObjectMessages. To be able to render ObjectMessages I need
> the class for the object contained in the message. Of course I don't
> know what this might be at compile time. So I need to provide a dialog
> where users can add the pathes to the classes for their ObjectMessage
> types. In the renderer component I need these classes in my classpath
> otherwise I get a ClassNotFoundException when I call
> message.getObject(). I tried URLClassLoader but it does not work. Maybe
> I am plain stupid but I do not see how to get that to work. I always end
> up in the DefaultClassLoader context.

The eclipse solution for this kind of problem is extension points and
extensions. You create an extension point, and allow users to create
extension to contribute classes that know how to specifically render
their ObjectMessage types.

Fooling around with classloaders in eclipse will end ... badly.

2 other options that come to mind. 1) actually provide class loading
hooks to OSGi, so that you can inject these classes at runtime or 2) do
the work for above for your clients, by dynamically whipping up a small
plugin and loading it for them.

Later,
PW


Re: Yet Another ClassLoader Question [message #465244 is a reply to message #465185] Mon, 26 March 2007 17:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Andreas.Fluegge.burningbush.de

Well, and here we come to the point. I can not call 'classForName'.
All I can do is calling 'getObject' on the message object I receive.
That's the problem. The object I retrieve from the message is a
serialized Java object.


CL 'dnoyeB' Gilbert schrieb:
> On Sat, 24 Mar 2007 22:12:04 +0100, Andreas Fluegge wrote:
>
>> Ok, here is more precisely what I want to do: I build a JMS browser. My
>> problem are ObjectMessages. To be able to render ObjectMessages I need
>> the class for the object contained in the message. Of course I don't
>> know what this might be at compile time. So I need to provide a dialog
>> where users can add the pathes to the classes for their ObjectMessage
>> types. In the renderer component I need these classes in my classpath
>> otherwise I get a ClassNotFoundException when I call
>> message.getObject(). I tried URLClassLoader but it does not work. Maybe
>> I am plain stupid but I do not see how to get that to work. I always end
>> up in the DefaultClassLoader context.
>>
>>
>
> It does not seem as if you are even using the URLClassloader. Your code
> must change. Can you show how you are using the URL classloadeR? it does
> not automatically append your classpath. you must call it explicitly with
> stuff like ClassForName.
Re: Yet Another ClassLoader Question [message #465264 is a reply to message #465244] Tue, 27 March 2007 11:24 Go to previous message
Eclipse UserFriend
Originally posted by: lamont_gilbert.rigidsoftware.com

On Mon, 26 Mar 2007 19:26:47 +0200, Andreas Fluegge wrote:

> Well, and here we come to the point. I can not call 'classForName'.
> All I can do is calling 'getObject' on the message object I receive.
> That's the problem. The object I retrieve from the message is a
> serialized Java object.
>
>

Yes, that would be the crux. 'serialization'. Its not directly an
Eclipse issue.

So your saying you have an application that you want to distribute to the
end user. And the end user will extend its classpath using a
URLClassloader so to speak. Then when objects are passed into your
'server' it will deserialize these objects with the help of the
URLclassloader if necessary.

Thats a tough one. It can be done, but it may be a bit complicated. If
you can change your architecture a bit it would be much easier.
Furthermore, its a bit insecure, but maybe not if the classes are local.
In any event, RMI accomplishes this using what it calls the 'codebase.'
it annotates the serialization stream on the client side with a
path to the classloader that can load the class. and during the
deserialization process it gets the classname and IIRC uses a form of
classForName.

I suspect you will have to modify your deserialization process to get the
classname out of the stream. Then use classForName somehow.


Look at
ObjectInputStream#resolveClass
ObjectOutputStream#annotateClass
Previous Topic:Using eclipse images in my plugin
Next Topic:How to add source code to Plug-in Dependencies
Goto Forum:
  


Current Time: Fri Sep 13 02:36:21 GMT 2024

Powered by FUDForum. Page generated in 0.06491 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top