Re: Dynamic Class loading
Suresh Babu Koya <[email protected]> Mon, 3 Jun 2002 15:02:08 +0530
| Newsgroups | gmane.comp.windows.devel.java.general |
|---|---|
| Message-ID | <7D5800A5B6E26644B2EB7A862856B0D4012EA4FD@SARASWATI> |
Thanks Rick. I was able to accomplish this with the URLClassLoader =
itself=20
without any need of extending the ClassLoader. I just instantiated the
URL class loader in the following way:
URLClassLoader ucl=3D new URLClassLoader( new URL[] {new
File(f1.getAbsolutePath()).toURL()} );
then I used the load class method and loaded the class:
Class c=3D ucl.loadClass(p.getProperty(myjarpath));
MyInterface fm =3D (MyInterface)c.newInstance();
> -----Original Message-----
> From: Christian Rick [mailto:[email protected]]
> Sent: Monday, June 03, 2002 2:20 PM
> To: [email protected]
> Subject: Re: [JAVA] Dynamic Class loading
>=20
>=20
> I once did something similar only that i loaded a class from=20
> a directory not
> specified in the classpath. What i did was to write my own subclass =
of
> ClassLoader and then use the following statements to load the class:
>=20
> Class ClassDesc =3D Class.forName("MyTestSubClass", false, =
new
> MyClassLoader());
> MyTestClass MySubClass =3D (MyTestClass)=20
> ClassDesc.newInstance();
> MySubClass.doSomething();
>=20
> I do not blelive that loading a class from a jar file should=20
> be any more
> difficult. If I remember right there are classes for handling=20
> jar files. If
> you want to look at my ClassLoader sublass please tell me and=20
> I'll email it
> to you.
>=20
>=20
> Best regards
> /Christian Rick
>=20
>=20
>=20
> -----Ursprungligt meddelande-----
> Fr=E5n: Suresh Babu Koya [mailto:[email protected]]
> Skickat: den 31 maj 2002 19:22
> Till: [email protected]
> =C4mne: [JAVA] Dynamic Class loading
>=20
>=20
> Hi all,
>=20
> Has anyone tried loading a class from a jar file not=20
> specified in the
> class path. I have tried to do that
> by modifying "java.class.path" after application startup=20
> and loading the
> class with Class.forName("com.xyz.test").
>=20
> While running I get a class not foung exception. How can I=20
> acheive my
> objective. Any help is appreciated.
>=20
> Regards,
> Suresh
>=20
> You can read messages from the JAVA archive, unsubscribe from JAVA,
> or subscribe to other DevelopMentor lists at=20
> http://discuss.develop.com.
>=20
> You can read messages from the JAVA archive, unsubscribe from JAVA,
> or subscribe to other DevelopMentor lists at=20
> http://discuss.develop.com.
>=20
You can read messages from the JAVA archive, unsubscribe from JAVA,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.