Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!.POSTED!not-for-mail From: BGB Newsgroups: comp.lang.java.programmer Subject: Re: resources from JAR files Date: Fri, 25 Jan 2013 15:08:52 -0600 Organization: albasani.net Lines: 32 Message-ID: References: <50f885a5$0$286$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.albasani.net VxkuMiZTIQMSXu18mhfqsFruwKFaSJlsNB6kJ0MW3+dfzKN6RHqAuTSiw7BWTFWTsWNQYh5CbHeuzMZYC8fUcOvrbsH3I5tOSzA2zonN1V5wYZY4In7k5MwHAL2hJnV5 NNTP-Posting-Date: Fri, 25 Jan 2013 21:10:15 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="FYQmNwKc/MTJE4wZuFeANgvCOY3BbVuTD6RStlY/NcNshIFGoO2QokW9SlWzTkVa9uXZoqbEE8ys3zlaoyODi5E2m1BQ26syh42Gw/UqO/jRvnzbPVgteXOwJ0wYUu5b"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: <50f885a5$0$286$14726298@news.sunsite.dk> Cancel-Lock: sha1:6FfwppyBeE1xUgUOAXPjlaZoVos= Xref: csiph.com comp.lang.java.programmer:21715 On 1/17/2013 5:13 PM, Arne Vajhøj wrote: > On 1/17/2013 11:30 AM, bob smith wrote: >> I have some code that reads an image from its JAR file like so: >> >> img = ImageIO.read(frame.getClass().getResource("whatever.jpg")); >> >> I basically just picked the "frame" object at random to call the >> getClass() method on it. >> >> Is there a way to do this without picking an arbitrary object? It >> seems so wrong. > > You need to pick either an object or a class. > > I think it is relative common to pick either this or the class. > FWIW, AFIAK: it can also be noted that it does matter which class you pick, like generally you want the class and resource file to be in the same package and JAR and similar (the class basically telling the JVM where to look, otherwise the resource may not be found). so, while a person can pick an arbitrary class, it may not necessarily find the resource. so, generally, picking 'this' or similar makes sense, since normally a person will package the resources along with their own code. or such...