Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ClassLoader Issues
ClassLoader Issues [message #449666] Wed, 17 May 2006 12:47 Go to next message
Eclipse UserFriend
Originally posted by: jbell80.msn.com

I am having a hard time adding folders/paths to the classloader at runtime
in an RCP app.

For example in a java application I am able to add a folder to the
classpath :

URL[] urlsToLoadFrom = new URL[]{ new URL("file:scripts/bin/") };
URLClassLoader loader = new URLClassLoader(urlsToLoadFrom);

Then I can access the classes and methods in that directory and pass in
references to classes that are already loaded (i.e. "this") :

scriptClass = Class.forName("myClass", true, loader);
initMethod = scriptClass.getDeclaredMethod("init", new Class[]
{this.class});
initMethod.invoke(null, new Object[]{this});

However, when I try this in an RCP app I get an error that the method
"init(my.Project.parameter)" cannot be found.

I am assuming that this has to do with the class that is calling the
"init" method and the actual "init" method are not in the same
classloader. I have tried using the current classloader but have not been
able to figure out how to add a URL to the current classloader.

If anyone has any ideas that may help - please let me know.

Thanks
Re: ClassLoader Issues [message #449669 is a reply to message #449666] Wed, 17 May 2006 13:05 Go to previous messageGo to next message
Eclipse UserFriend
Jon Bell wrote:
> I am having a hard time adding folders/paths to the classloader at
> runtime in an RCP app.
> For example in a java application I am able to add a folder to the
> classpath :
> URL[] urlsToLoadFrom = new URL[]{ new URL("file:scripts/bin/") };
> URLClassLoader loader = new URLClassLoader(urlsToLoadFrom);
>


To understand classloading Alex's article is a good place to start:
http://www.eclipsezone.com/articles/eclipse-vms/

Eclipse bundles manage their own classpaths, and normally don't allow
modifications are runtime.

Other than that, I think that there were a couple of newsgroup articles
in the last 2 weeks on how you could get your own classloader to work
with eclipse, but I'm not sure ... it's not an easy thing.

Later,
PW
Re: ClassLoader Issues [message #449693 is a reply to message #449666] Wed, 17 May 2006 16:54 Go to previous message
Eclipse UserFriend
I'm not quite understand your code but notice 2 things that look to me strange


1.
It looks like that like is working:
scriptClass = Class.forName("myClass", true, loader);
but next does not...

Try to create you class loader with parent:

URLClassLoader(URL[] urls, ClassLoader parent)

As parent use this.getClass().getClassloader()

It should help.

2.
file:scripts/bin/ - this is a relative path. In RPC application it would counted from
"install" directory (directory from where your run your application). Would it be better
to use absolute path file:///scripts/bin/.


Best regards

Ram


Jon Bell wrote:
> I am having a hard time adding folders/paths to the classloader at
> runtime in an RCP app.
> For example in a java application I am able to add a folder to the
> classpath :
> URL[] urlsToLoadFrom = new URL[]{ new URL("file:scripts/bin/") };
> URLClassLoader loader = new URLClassLoader(urlsToLoadFrom);
>
> Then I can access the classes and methods in that directory and pass in
> references to classes that are already loaded (i.e. "this") :
>
> scriptClass = Class.forName("myClass", true, loader);
> initMethod = scriptClass.getDeclaredMethod("init", new Class[]
> {this.class});
> initMethod.invoke(null, new Object[]{this});
>
> However, when I try this in an RCP app I get an error that the method
> "init(my.Project.parameter)" cannot be found.
>
> I am assuming that this has to do with the class that is calling the
> "init" method and the actual "init" method are not in the same
> classloader. I have tried using the current classloader but have not
> been able to figure out how to add a URL to the current classloader.
>
> If anyone has any ideas that may help - please let me know.
>
> Thanks
>
cs
Previous Topic:Branding the Help Index Page
Next Topic:removing console icons
Goto Forum:
  


Current Time: Sun Aug 31 15:44:06 EDT 2025

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

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

Back to the top