Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: Roedy Green Newsgroups: comp.lang.java.programmer Subject: Re: resources from JAR files Date: Thu, 17 Jan 2013 15:07:33 -0800 Organization: Canadian Mind Products Lines: 24 Message-ID: References: Reply-To: Roedy Green NNTP-Posting-Host: K2Qzzs3EAqXk5RLzfhxcSw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Forte Agent 6.00/32.1186 Xref: csiph.com comp.lang.java.programmer:21498 On Thu, 17 Jan 2013 08:30:23 -0800 (PST), bob smith wrote, quoted or indirectly quoted someone who said : >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. It is really just looking for a package name to find the resource. You can name the main class explicitly MyProg.class or this.getClass() There is no Package class, so they use Class. You want something in YOUR package. see http://mindprod.com/jgloss/resource.html -- Roedy Green Canadian Mind Products http://mindprod.com The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ~ Tom Cargill Ninety-ninety Law