Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.CARNet.hr!gregory.BNet.hr!not-for-mail From: Josip Almasi Newsgroups: comp.lang.java.programmer Subject: Re: limitations of Class.forName Date: Fri, 02 May 2014 09:25:53 +0200 Organization: B.net Hrvatska d.o.o. Lines: 38 Message-ID: References: NNTP-Posting-Host: cpe-188-252-130-182.zg5.cable.xnet.hr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: gregory.bnet.hr 1399015553 9029 188.252.130.182 (2 May 2014 07:25:53 GMT) X-Complaints-To: abuse@globalnet.hr NNTP-Posting-Date: Fri, 2 May 2014 07:25:53 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:28351 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...