ClassLoader Issues [message #449666] |
Wed, 17 May 2006 12:47  |
Eclipse User |
|
|
|
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 #449693 is a reply to message #449666] |
Wed, 17 May 2006 16:54  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.03361 seconds