Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #28351
| From | Josip Almasi <joe@vrspace.org> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: limitations of Class.forName |
| Date | 2014-05-02 09:25 +0200 |
| Organization | B.net Hrvatska d.o.o. |
| Message-ID | <ljvha1$8q5$1@gregory.bnet.hr> (permalink) |
| References | <p5q5m916vc7ued437313f6ghvac4slirrq@4ax.com> |
On 05/02/2014 02:42 AM, Roedy Green wrote: > When I first encountered Java, I was very excited about the notion > of interfaces and dynamic loading. I thought it would let people plug > in their own code to every conceivable utility. > > There are two catches. > > 1. arranging that java.exe will look for your dynamic class in the > place where it is. It will not usually be bundled in the original > jar. > > 2. arranging that java.exe will look for any auxiliary classes your > plugin needs in the place where they live. Oh, but there's more. Class.equals() will fail on classes loaded by different classloaders, as will Object.equals(). That is, after you extend URLClassLoader as Arne said:) Then, you can't unload a class just like that, as class loader keeps references to all loaded classes. You need to unload that ClassLoader too. That is, if you wish to reload plugins without jvm restart. With custom URLClassLoader, watch carefully not to break specified delegation model. > A garden variety jar prevents java from looking anywhere else for > classes. > > I thought I would write a short essay on this. What techniques are > available? > > I have always skirted the problem by putting all classes in the > original jar. OK then you wish only to customize application classloader. Note that in JEE containers, classloaders have another important function - context isolation. Regards...
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
limitations of Class.forName Roedy Green <see_website@mindprod.com.invalid> - 2014-05-01 17:42 -0700
Re: limitations of Class.forName Arne Vajhøj <arne@vajhoej.dk> - 2014-05-01 21:15 -0400
Re: limitations of Class.forName Robert Klemme <shortcutter@googlemail.com> - 2014-05-02 08:51 +0200
Re: limitations of Class.forName Josip Almasi <joe@vrspace.org> - 2014-05-02 09:25 +0200
Re: limitations of Class.forName Roedy Green <see_website@mindprod.com.invalid> - 2014-05-06 03:55 -0700
csiph-web