Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #2431 > unrolled thread
| Started by | "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:39 +0000 |
| Last post | 2011-04-27 15:39 +0000 |
| Articles | 10 — 6 participants |
Back to article view | Back to comp.lang.java.gui
how to set image path "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: how to set image path a24900@googlemail.com.remove-dii-this - 2011-04-27 15:39 +0000
Re: how to set image path "Lew" <lew@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: how to set image path a24900@googlemail.com.remove-dii-this - 2011-04-27 15:39 +0000
Re: how to set image path "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: how to set image path "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: how to set image path "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: how to set image path "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
Re: how to set image path a24900@googlemail.com.remove-dii-this - 2011-04-27 15:39 +0000
Re: how to set image path "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:39 +0000
| From | "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Subject | how to set image path |
| Message-ID | <1189711839.468323.96930@k79g2000hse.googlegroups.com> |
To: comp.lang.java.gui
How can I specify which folder JVM will look for images?
I use getClass().getClassLoader().getResource("myimage")
Right now it looks in ../ directory but I would really like it to look
in my ../../src/ directory
is this possible?
thanks
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | a24900@googlemail.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <1189715013.849159.282880@w3g2000hsg.googlegroups.com> |
| In reply to | #2431 |
To: comp.lang.java.gui
On Sep 13, 9:30 pm, marcussilf...@gmail.com wrote:
> How can I specify which folder JVM will look for images?
> I use getClass().getClassLoader().getResource("myimage")
> Right now it looks in ../ directory but I would really like it to look
> in my ../../src/ directory
Put the path for the image directory on the classpath. But your whole
question smells as if you have messed up your classpath and build
settings. You do not want to have to look around in your source
environment for resources. The resources should have been copied into
the target (class directory or jar).
Also, consider using getClass().getResource(). It has a slightly
different way to search for resources compared to
getClass().getClassLoader().getResource() when the resource name
starts with "/". This "absolute" way to search for resources is often
what you want.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Lew" <lew@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <Yu-dndntd8gNQnTbnZ2dnUVZ_vninZ2d@comcast.com> |
| In reply to | #2432 |
To: comp.lang.java.gui
#
+2Path: textnews.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!81.171.88.9.MISMATCH!ramfeed2.eweka.nl!eweka.nl!lightspeed.eweka.nl!postnews.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail
NNTP-Posting-Date: Thu, 13 Sep 2007 20:10:40 -0500
Date: Thu, 13 Sep 2007 21:10:40 -0400
From: Lew <lew@lewscanon.com>
User-Agent: Thunderbird 2.0.0.5 (X11/20070719)
MIME-Version: 1.0
Newsgroups: comp.lang.java.gui
Subject: Re: how to set image path
References: <1189711839.468323.96930@k79g2000hse.googlegroups.com> <1189715013.849159.282880@w3g2000hsg.googlegroups.com>
In-Reply-To: <1189715013.849159.282880@w3g2000hsg.googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <Yu-dndntd8gNQnTbnZ2dnUVZ_vninZ2d@comcast.com>
Lines: 26
X-Usenet-Provider: http://www.giganews.com
NNTP-Posting-Host: 76.114.174.111
X-Trace: sv3-BasUvUilD009RkDWB8eFVuDa5ojSnwhAsB4YlBGql7UaZy04+3hGWIRAomC6KDUUU2OsmAsP5oS8DTi!JOtS/WKSitBm2ffeclkJf0wf5VP0zbWzB09nAbYw3oWgfdKHMSf3e0oSjw/2l3moeDvS51FBrr0X!65p3G84TF7wJr9x9TbXL0bxDEJYiUcw=
X-Complaints-To: abuse@comcast.net
X-DMCA-Complaints-To: dmca@comcast.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.36
Xref: textnews.cambrium.nl comp.lang.java.gui:16448
a24900@googlemail.com wrote:
> On Sep 13, 9:30 pm, marcussilf...@gmail.com wrote:
>> How can I specify which folder JVM will look for images?
>> I use getClass().getClassLoader().getResource("myimage")
>> Right now it looks in ../ directory but I would really like it to look
>> in my ../../src/ directory
>
> Put the path for the image directory on the classpath. But your whole
> question smells as if you have messed up your classpath and build
> settings. You do not want to have to look around in your source
> environment for resources. The resources should have been copied into
> the target (class directory or jar).
>
> Also, consider using getClass().getResource(). It has a slightly
> different way to search for resources compared to
> getClass().getClassLoader().getResource() when the resource name
> starts with "/". This "absolute" way to search for resources is often
> what you want.
Good advice, but I believe in relative paths myself.
Since one of the purposes of Java is portability, one should avoid hardcoded
absolute paths as they are not portable.
--
Lew
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | a24900@googlemail.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <1189783730.991711.301350@y42g2000hsy.googlegroups.com> |
| In reply to | #2435 |
To: comp.lang.java.gui On Sep 14, 3:10 am, Lew <l...@lewscanon.com> wrote: > Good advice, but I believe in relative paths myself. > > Since one of the purposes of Java is portability, one should avoid hardcoded > absolute paths as they are not portable. These "absolute" resource parts are portable, because they start "relatively" from the "roots" of classpath elements. Example: If you have a classpath with /pathA:/pathB:/C.jar:/D.jar then a resource called /images/imageA.png is searched 1) relative to /pathA as /pathA/images/imageA.png if not found 2) relative to /pathB as /pathB/images/imageA.png if not found 3) "Absolute" in the jar /C.jar as a jar/zip file entry with the name / images/imageA.png if not found 4) "Absolute" in the jar /D.jar as a jar/zip file entry with the name / images/imageA.png I consider the last two parts of the example, 3) and 4), the most important ones, since it means I can fully predict which names I have to use when packing the resources into the jar. And I can put exactly these names into my code as arguments to Class.getResource() I consider that as more flexible, fully portable and providing more control than having to mess with ../../something. Such a resource name can break as soon as I e.g. refactor the package name of the class from which I look up the resource. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <1189774555.759691.275480@y42g2000hsy.googlegroups.com> |
| In reply to | #2432 |
To: comp.lang.java.gui
> Also, consider using getClass().getResource(). It has a slightly
> different way to search for resources compared to
> getClass().getClassLoader().getResource() when the resource name
> starts with "/". This "absolute" way to search for resources is often
> what you want.
Thanks for answering.
I must use relative paths, my resource names does not start with "/".
I may not have been all that clear in my previous post.
> The resources should have been copied into
> the target (class directory or jar).
>
I can not put the resources in my class directory, since I use Jigloo
GUI builder which dont allow me to specify images in other directories
but the "src" directory or subfolders of it. When running my app the
JVM looks in the bin folder for the image.
my directory hierarchy looks like this:
myProject
bin
myapp_classes // classes generated from my java source by
Eclipse
images // these images are found by JVM, but not by
Jigloo
src
myapp_src // my java source code
images // these images are found by Jigloo, but not by
JVM
So right now I have 2 folders named "images" containing all my images.
One is placed as a subfolder of the bin folder and the other is placed
as a subfolder of the src folder. The content of the images folders
are identical.
If I delete the bin/images/ folder then the image will not be found at
runtime, they will be found by Jigloo though.
If I instead deletes the src/images/ folder then no image will be seen
in Jigloo, they will be found at runtime though.
What can I do to make JVM and Jigloo use the same path for images? I
see 2 solutions to this:
1) have 2 "images" directories (like my current solution)
2) have both .class files and .java files on the class path, like
MyProject
src
myapp_src_and_classes
images
Any other ideas on the best way to solve this?
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "marcussilfver" <marcussilfver@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <1189774922.432308.182100@22g2000hsm.googlegroups.com> |
| In reply to | #2436 |
To: comp.lang.java.gui I send this post because my previous was linebreaked in a way that made the directory hierarkies hard to read. Same content otherwise. Read this one instead. > > Also, consider using getClass().getResource(). It has a slightly > > different way to search for resources compared to > > getClass().getClassLoader().getResource() when the resource name > > starts with "/". This "absolute" way to search for resources is often > > what you want. > > Thanks for answering. > I must use relative paths, my resource names does not start with "/". > I may not have been all that clear in my previous post. > > > The resources should have been copied into > > the target (class directory or jar). > > I can not put the resources in my class directory, since I use Jigloo > GUI builder which dont allow me to specify images in other directories > but the "src" directory or subfolders of it. When running my app the > JVM looks in the bin folder for the image. > > my directory hierarchy looks like this: > > myProject > bin > myapp_classes // generated from my java source > images // found by JVM, but not by Jigloo > src > myapp_src // java source code > images // found by Jigloo, but not by JVM > > So right now I have 2 folders named "images" containing all my images. > One is placed as a subfolder of the bin folder and the other is placed > as a subfolder of the src folder. The content of the images folders > are identical. > If I delete the bin/images/ folder then the image will not be found at > runtime, they will be found by Jigloo though. > If I instead deletes the src/images/ folder then no image will be seen > in Jigloo, they will be found at runtime though. > > What can I do to make JVM and Jigloo use the same path for images? I > see 2 solutions to this: > 1) have 2 "images" directories (like my current solution) > 2) have both .class files and .java files on the class path, like > MyProject > src > myapp_src_and_classes > images > > Any other ideas on the best way to solve this? --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <7834c495ea66f@uwe> |
| In reply to | #2436 |
To: comp.lang.java.gui marcussilfver@gmail.com wrote: .. >What can I do to make JVM and Jigloo use the same path for images? I am going to make a WAG* that this question really reduces to running a 'built' project, as opposed to running it from the local filesystem If that WAG turns out to be correct, I suggest you use Ant to build the project, never try and test it as 'loose' class files, and proceed beyond this (apparent) difficulty. * Without even reading the entire post properly. (shrugs) Sue me. -- Andrew Thompson http://www.athompson.info/andrew/ Message posted via JavaKB.com http://www.javakb.com/Uwe/Forums.aspx/java-gui/200709/1 --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Nigel Wade" <nigel.wade@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <fce24k$o9k$1@south.jnrs.ja.net> |
| In reply to | #2436 |
To: comp.lang.java.gui
marcussilfver@gmail.com wrote:
>> Also, consider using getClass().getResource(). It has a slightly
>> different way to search for resources compared to
>> getClass().getClassLoader().getResource() when the resource name
>> starts with "/". This "absolute" way to search for resources is often
>> what you want.
>
> Thanks for answering.
> I must use relative paths, my resource names does not start with "/".
> I may not have been all that clear in my previous post.
>
>> The resources should have been copied into
>> the target (class directory or jar).
>>
>
> I can not put the resources in my class directory, since I use Jigloo
> GUI builder which dont allow me to specify images in other directories
> but the "src" directory or subfolders of it. When running my app the
> JVM looks in the bin folder for the image.
>
> my directory hierarchy looks like this:
>
> myProject
> bin
> myapp_classes // classes generated from my java source by
> Eclipse
> images // these images are found by JVM, but not by
> Jigloo
> src
> myapp_src // my java source code
> images // these images are found by Jigloo, but not by
> JVM
>
> So right now I have 2 folders named "images" containing all my images.
> One is placed as a subfolder of the bin folder and the other is placed
> as a subfolder of the src folder. The content of the images folders
> are identical.
> If I delete the bin/images/ folder then the image will not be found at
> runtime, they will be found by Jigloo though.
> If I instead deletes the src/images/ folder then no image will be seen
> in Jigloo, they will be found at runtime though.
>
> What can I do to make JVM and Jigloo use the same path for images? I
> see 2 solutions to this:
> 1) have 2 "images" directories (like my current solution)
> 2) have both .class files and .java files on the class path, like
> MyProject
> src
> myapp_src_and_classes
> images
>
> Any other ideas on the best way to solve this?
I'm not sure what the ideal solution would be. Probably to use ant to create a
distribution jar containing the classes and the images, and then run that.
One less than ideal solution, if this is Linux or UNIX as the path names appear
to be, would be to either hard or symbolic link the two image directories. At
least that way you would only have one actual image directory, with the other
being a link to it. There would only be one copy of each image, and only one
directory to maintain.
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | a24900@googlemail.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <1189784052.591736.144570@o80g2000hse.googlegroups.com> |
| In reply to | #2436 |
To: comp.lang.java.gui On Sep 14, 2:55 pm, marcussilf...@gmail.com wrote: > I must use relative paths, my resource names does not start with "/". Which is IMHO one of your problems. > I can not put the resources in my class directory, since I use Jigloo > GUI builder which dont allow me to specify images in other directories The your tool is broken and you should consider using something else. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:39 +0000 |
| Message-ID | <bc9le35g1fnaclve2qmdrqojrtchmfosuk@4ax.com> |
| In reply to | #2431 |
To: comp.lang.java.gui
On Thu, 13 Sep 2007 12:30:39 -0700, marcussilfver@gmail.com wrote,
quoted or indirectly quoted someone who said :
>How can I specify which folder JVM will look for images?
>I use getClass().getClassLoader().getResource("myimage")
>Right now it looks in ../ directory but I would really like it to look
>in my ../../src/ directory
The image path is the same as the classpath. See
http://mindprod.com/jgloss/classpath.html for how the classpath works.
Usually you put resources in a jar file where you have better control
over them.
see http://mindprod.com/jgloss/jar.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web