Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11628

Re: Resource confusion

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: Resource confusion
Date Sat, 28 Jan 2012 13:43:12 -0800
Organization albasani.net
Lines 55
Message-ID <jg1q5g$3k3$1@news.albasani.net> (permalink)
References <Xns9FE8824D28F28jpnasty@94.75.214.39> <UeYUq.127$V94.98@newsfe21.iad>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net M63d/6XLKkHu+jJU5HUABrhYXfTKl2zYJb0kVlDHWkB8fxqUzWug8nQu/K0nmoMEcntXPnpnHWlAgVyVXOuYsSlNAkC+X5Pka2J6+RrPW3N3Rw68hcoiuZMI9oGgUW5X
NNTP-Posting-Date Sat, 28 Jan 2012 21:43:13 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="jEbEOISZAEh/aZgUoIJgs5oNJqRxWms91AY3FKzH40guliT+LFMKfUzLOarxr9FZPg+aqKrwfZLEwlDk8v8PCGeb6eriFqpxeaI+SrLP248UMFWZ4jd48ucjmmxFgwft"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0
In-Reply-To <UeYUq.127$V94.98@newsfe21.iad>
Cancel-Lock sha1:gIs4XsQLUAuDfOEecGy3IlFeqy0=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11628

Show key headers only | View raw


Arved Sandstrom wrote:
> If you're going to use .getResource(), the String "name" that you supply
> is actually a '/'-separated path name that identifies something on a
> classloader classpath. You have a number of classloaders involved every
> time you run your app; fact is that your phrase-list file (even if you
> had a '/'-separated path spec for it) very likely isn't on the classpath
> for any of those classloaders.
>
> It doesn't sound to me like you need either the getResource() or
> getResourceAsStream() approaches (which are available through
> ClassLoader or delegated from Class); you might be better off saving and
> using file URLs.
>
> The exact form of a file URL varies across systems but they all have the
> file: scheme. On a UNIX system
>
> URL phraseListUrl = new URL("file:///home/me/Games/PhraseLists");
>
> would work, but off the top of my head on a Windows box it's something like
>
> URL phraseListUrl = new URL("file:///C:/Games/PhraseLists");
>
> This is just informational, because your app doesn't have to construct
> these things, just save them. Your user does the heavy lifting by
> selecting the location with a file chooser; that gives you a File
> object. You can save out the result with
>
> userSelectedFile.toURI().toURL().toString()
>
> To return to getResource() or getResourceAsStream(), and classloaders:
> the situation is more complicated in Java application server
> environments [1], and for this reason context classloaders were made
> available as (imperfect) solutions. But you are not in that scenario.
>
> I'll also add that *if* it made sense for you to have a file resource on
> the classpath, and you were using getResource() or
> getResourceAsStream(), it doesn't make sense for you to pose the
> question "which classloader should I use?" That's not *your* decision to
> make, per se - you can influence that choice by where you place the
> resource, but you don't directly select a classloader (again, unless you
> were in a server environment and using a context classloader).
>
> AHS
>
> 1. As anyone can attest who has spent quality hours wrestling with a
> situation where instance 1 of class X hasn't the same class as instance
> 2 of class X...for various reasons.

What he said, only adding tangentially that at some not-too-distant future 
point it pays to understand classloading in Java.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Resource confusion Novice <novice@example..com> - 2012-01-28 17:47 +0000
  Re: Resource confusion Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-28 15:44 -0400
    Re: Resource confusion Lew <noone@lewscanon.com> - 2012-01-28 13:43 -0800
    Re: Resource confusion Novice <novice@example..com> - 2012-01-29 05:40 +0000
      Re: Resource confusion Lew <noone@lewscanon.com> - 2012-01-28 22:43 -0800
      Re: Resource confusion Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-29 13:24 -0400
  Re: Resource confusion Roedy Green <see_website@mindprod.com.invalid> - 2012-01-30 13:33 -0800
    Re: Resource confusion Martin Gregorie <martin@address-in-sig.invalid> - 2012-01-31 02:45 +0000
      Re: Resource confusion Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-31 06:32 -0400
        Re: Resource confusion Martin Gregorie <martin@address-in-sig.invalid> - 2012-01-31 20:43 +0000
          Re: Resource confusion Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-01-31 18:08 -0400
            Re: Resource confusion Martin Gregorie <martin@address-in-sig.invalid> - 2012-01-31 23:01 +0000

csiph-web