
Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
On 30 Mar, 09:22, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Sat, 29 Mar 2008 09:07:36 -0700 (PDT), strus_82
> <marcin.strug...@gmail.com> wrote, quoted or indirectly quoted someone
[quoted text clipped - 9 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com
Hello,
I'm trying to write my ClassLoader but I have the following problem:
when I read all data from .class (here it is CustomClassLoader.class)
file to byte array - I call defineClass() but an exception is thrown:
"d:/examples/temp/CustomClassLoader (wrong name: CustomClassLoader)".
I think I pass wrong first parameter to defineClass(String name,
byte[] b, int off, int len). The CustomClassLoader.class file is
located in d:\examples\temp\.
I have also tried to use findClass() but it's the same.
I have tried different combination of the path to that .class file but
the result is the same all the time :/
Could You give me some hint? All I want to do (for couple hours :/) is
to load class from some path of the local file system (but the path is
not set in CLASS PATH).
Thanks in advance,
M.
Arne Vajhøj - 30 Mar 2008 22:19 GMT
> I'm trying to write my ClassLoader but I have the following problem:
> when I read all data from .class (here it is CustomClassLoader.class)
[quoted text clipped - 13 lines]
> to load class from some path of the local file system (but the path is
> not set in CLASS PATH).
It is much simpler than that !
URLClassLoader cl = new URLClassLoader("file:/d:/examples/temp/");
Object o = Class.forName("mypackage.MyClass", true, cl).newInstance();
will load mypackage.MyClass from D:\examples\temp\mypackage\MyClass.class !
Arne
strus_82 - 30 Mar 2008 22:39 GMT
> It is much simpler than that !
>
[quoted text clipped - 4 lines]
>
> Arne
Indeed :) thx. I've tried this but I used toURL() as a argument to
URLClassLoader (it takes URL[]) - but this toURL() is deprecated
starting from v.1.5, bur as You wrote I can use simply a string:
URLClassLoader(new URL[] {new URL("file:/d:/examples/temp/")});
But could you tell me what I did wrong in case of defining my
ClassLoader?
Best regards,
M.