Home » Newcomers » Newcomers » Loading resources via Classloader
Loading resources via Classloader [message #265941] |
Wed, 29 October 2008 20:36 |
Eclipse User |
|
|
|
Originally posted by: riwright.adobe.com
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3308132174_18042391
Content-type: text/plain;
charset="ISO-8859-1"
Content-transfer-encoding: 8bit
I have a number of plugins for various uses. Sometimes I need to load
resources, such as image files, etc. I usually do it via
MyClass.class.getClassLoader.GetResource(resourceName). This works fine in
plugins. But if I use this in a simple Java app (e.g. With a static main()
method) the loading of the resource always fails. The classloader finds the
various classes of the app without problem, but can
|
|
|
Re: Loading resources via Classloader [message #265942 is a reply to message #265941] |
Wed, 29 October 2008 23:31 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------070605090400050907070100
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ric,
The resource is in the same package/folder? It's properly in the final
jar or the bin folder in the right place? Does removing the
getClassLoader() make a difference.
Ric Wright wrote:
> I have a number of plugins for various uses. Sometimes I need to load
> resources, such as image files, etc. I usually do it via
> MyClass.class.getClassLoader.GetResource(resourceName). This works
> fine in plugins. But if I use this in a simple Java app (e.g. With a
> static main() method) the loading of the resource always fails. The
> classloader finds the various classes of the app without problem, but
> can't seem to find the resource.
>
> Is there a good way to do this? Or am I simply missing something?
>
> TIA,
> Ric
--------------070605090400050907070100
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ric,<br>
<br>
The resource is in the same package/folder? It's properly in the final
jar or the bin folder in the right place? Does removing the
getClassLoader() make a difference.<br>
<br>
<br>
Ric Wright wrote:
<blockquote cite="mid:C52E1747.47328%25riwright@adobe.com" type="cite">
<title>Loading resources via Classloader</title>
<font face="Verdana, Helvetica, Arial"><span style="font-size: 11pt;">I
have a number of plugins for various uses. Sometimes I need to load
resources, such as image files, etc. I usually do it via
MyClass.class.getClassLoader.GetResource(resourceName). This works
fine in plugins. But if I use this in a simple Java app (e.g. With a
static main() method) the loading of the resource always fails. The
classloader finds the various classes of the app without problem, but
can’t seem to find the resource.<br>
<br>
Is there a good way to do this? Or am I simply missing something?<br>
<br>
TIA,<br>
Ric</span></font>
</blockquote>
</body>
</html>
--------------070605090400050907070100--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Loading resources via Classloader [message #265945 is a reply to message #265942] |
Wed, 29 October 2008 23:55 |
Eclipse User |
|
|
|
Originally posted by: riwright.adobe.com
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3308144142_18754278
Content-type: text/plain;
charset="ISO-8859-1"
Content-transfer-encoding: 8bit
Ed,
No, what I do is create a /resource folder in src as peer to the packages.
Then I address the resource as /resource/myimage.gif. Even if I copy it
into the bin folder it still fails. And the usual method (where it is in
/resource folder) works fine if it is a plugin, but not if it is a Java
applet. So I feel that the key has to be in how the classloader works
differently from a plugin to an applet. But I am not expert in
classloaders, that
|
|
|
Re: Loading resources via Classloader [message #265948 is a reply to message #265945] |
Thu, 30 October 2008 00:31 |
Eclipse User |
|
|
|
Originally posted by: riwright.adobe.com
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3308146297_18852062
Content-type: text/plain;
charset="ISO-8859-1"
Content-transfer-encoding: 8bit
Just to clarify, I am not running an applet, but a simple Java app, i.e. A
class with a static main() method.
I have done a little more reading, including this article on Sun
|
|
|
Re: Loading resources via Classloader [message #265951 is a reply to message #265948] |
Thu, 30 October 2008 00:58 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------040903080708000601080706
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ric,
So what string exactly are you passing in? If you try "." or "/" as the
resource name and look at the URL that comes back, what does it look
like? It's quite common to put the resource in the same folder as the
package and then load it with a relative name, but your approach ought
to work too...
PS. Don't use reply all on newsgroup posting, just reply to the
newsgroup itself.
Ric Wright wrote:
> Just to clarify, I am not running an applet, but a simple Java app,
> i.e. A class with a static main() method.
>
> I have done a little more reading, including this article on Sun's site:
> http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l
>
> From reading that, it looks like it should work, and with a plugin it
> does. But with an app it does not, no matter where I put the resource
> or how I address it. I'll confess to being somewhat stymied at this
> point.
>
> Ric
>
>
> On 10/29/08 4:55 PM, in article C52E460B.47F10%riwright@adobe.com,
> "Ric Wright" <riwright@adobe.com> wrote:
>
> Ed,
>
> No, what I do is create a /resource folder in src as peer to the
> packages. Then I address the resource as /resource/myimage.gif.
> Even if I copy it into the bin folder it still fails. And the
> usual method (where it is in /resource folder) works fine if it is
> a plugin, but not if it is a Java applet. So I feel that the key
> has to be in how the classloader works differently from a plugin
> to an applet. But I am not expert in classloaders, that's for sure.
>
> Thanks,
> Ric
>
>
>
> On 10/29/08 4:31 PM, in article gearpj$pv1$2@build.eclipse.org,
> "Ed Merks" <Ed.Merks@gmail.com> wrote:
>
> Ric,
>
> The resource is in the same package/folder? It's properly in
> the final jar or the bin folder in the right place? Does
> removing the getClassLoader() make a difference.
>
>
> Ric Wright wrote:
>
> Loading resources via Classloader I have a number of
> plugins for various uses. Sometimes I need to load
> resources, such as image files, etc. I usually do it via
> MyClass.class.getClassLoader.GetResource(resourceName).
> This works fine in plugins. But if I use this in a
> simple Java app (e.g. With a static main() method) the
> loading of the resource always fails. The classloader
> finds the various classes of the app without problem, but
> can't seem to find the resource.
>
> Is there a good way to do this? Or am I simply missing
> something?
>
> TIA,
> Ric
>
>
>
--------------040903080708000601080706
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Ric,<br>
<br>
So what string exactly are you passing in? If you try "." or "/" as
the resource name and look at the URL that comes back, what does it
look like? It's quite common to put the resource in the same folder as
the package and then load it with a relative name, but your approach
ought to work too...<br>
<br>
PS. Don't use reply all on newsgroup posting, just reply to the
newsgroup itself.<br>
<br>
<br>
<br>
Ric Wright wrote:
<blockquote cite="mid:C52E4E77.47F1A%25riwright@adobe.com" type="cite">
<title>Re: Loading resources via Classloader</title>
<font face="Verdana, Helvetica, Arial"><span style="font-size: 11pt;">Just
to clarify, I am not running an applet, but a simple Java app, i.e. A
class with a static main() method. <br>
<br>
I have done a little more reading, including this article on Sun’s site:<br>
<a moz-do-not-send="true"
href=" http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l"> http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l</a><br>
<br>
From reading that, it looks like it should work, and with a plugin it
does. But with an app it does not, no matter where I put the resource
or how I address it. I’ll confess to being somewhat stymied at this
point.<br>
<br>
Ric<br>
<br>
<br>
On 10/29/08 4:55 PM, in article <a moz-do-not-send="true"
href="C52E460B.47F10%riwright@adobe.com">C52E460B.47F10%riwright@adobe.com</a>,
"Ric Wright" <<a moz-do-not-send="true" href="riwright@adobe.com">riwright@adobe.com</a>>
wrote:<br>
<br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;">Ed,<br>
<br>
No, what I do is create a /resource folder in src as peer to the
packages. Then I address the resource as /resource/myimage.gif. Even
if I copy it into the bin folder it still fails. And the usual method
(where it is in /resource folder) works fine if it is a plugin, but not
if it is a Java applet. So I feel that the key has to be in how the
classloader works differently from a plugin to an applet. But I am not
expert in classloaders, that’s for sure.<br>
<br>
Thanks,<br>
Ric<br>
<br>
<br>
<br>
On 10/29/08 4:31 PM, in article <a moz-do-not-send="true"
href="gearpj$pv1$2@build.eclipse.org">gearpj$pv1$2@build.eclipse.org</a>,
"Ed Merks" <<a moz-do-not-send="true" href="Ed.Merks@gmail.com">Ed.Merks@gmail.com</a>>
wrote:<br>
<br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;">Ric,<br>
<br>
The resource is in the same package/folder? It's properly in the final
jar or the bin folder in the right place? Does removing the
getClassLoader() make a difference.<br>
<br>
<br>
Ric Wright wrote: <br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"> Loading resources via Classloader I have a
number of plugins for various uses. Sometimes I need to load
resources, such as image files, etc. I usually do it via
MyClass.class.getClassLoader.GetResource(resourceName). This works
fine in plugins. But if I use this in a simple Java app (e.g. With a
static main() method) the loading of the resource always fails. The
classloader finds the various classes of the app without problem, but
can’t seem to find the resource.<br>
<br>
Is there a good way to do this? Or am I simply missing something?<br>
<br>
TIA,<br>
Ric <br>
</span></font></blockquote>
<font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"><br>
</span></font></blockquote>
<font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"><br>
</span></font></blockquote>
</blockquote>
</body>
</html>
--------------040903080708000601080706--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Progress - Re: Loading resources via Classloader [message #265962 is a reply to message #265948] |
Thu, 30 October 2008 18:26 |
Eclipse User |
|
|
|
Originally posted by: riwright.adobe.com
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3308210816_19921192
Content-type: text/plain;
charset="ISO-8859-1"
Content-transfer-encoding: 8bit
Well, I found a solution, but do not know why it makes a difference. The
solution is that instead of
this.getClass().getClassLoader().getResource(resourceName);
Use
this.getClass().getResource(resourceName);
The latter works for both plugins and for Java apps. Now the Javadoc for
Class says that getResource delegates the call to its classloader, so it
isn
|
|
|
Re: Progress - Re: Loading resources via Classloader [message #265965 is a reply to message #265962] |
Thu, 30 October 2008 18:46 |
Ed Merks Messages: 33264 Registered: July 2009 |
Senior Member |
|
|
This is a multi-part message in MIME format.
--------------030409070605070506060301
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ric,
I had a bad feeling about that; recall my asking if removing
getClassLoader() made a difference? I'm not an expert at this black
magic, but if you think about it, lots of classes will share the same
class loader (maybe all of them in a stand-alone application) so you
kind of lose the context when you don't call the method directly on the
class. Sure the class delegates to the class loader, but then the
class calling the class loader is on the class stack, whereas with what
you did, it's not. Likely that makes all the difference between being
able to resolve the path relative to the calling class, or relative to
goodness knows what. So why does it work with Eclipse the way you head
it? Probably because for Eclipse, each bundle has its own class loader,
so the class loader has more context than it does stand alone. Of
course I could be full of hot air too...
Ric Wright wrote:
> Well, I found a solution, but do not know why it makes a difference.
> The solution is that instead of
>
> this.getClass().getClassLoader().getResource(resourceName);
>
> Use
>
> this.getClass().getResource(resourceName);
>
> The latter works for both plugins and for Java apps. Now the Javadoc
> for Class says that getResource delegates the call to its classloader,
> so it isn't clear to me why there would be any difference between the
> two. Could some classLoader maven out there cast some light on this?
>
> TIA, Ric
>
> On 10/29/08 5:31 PM, in article C52E4E77.47F1A%riwright@adobe.com,
> "Ric Wright" <riwright@adobe.com> wrote:
>
> Just to clarify, I am not running an applet, but a simple Java
> app, i.e. A class with a static main() method.
>
> I have done a little more reading, including this article on Sun's
> site:
> http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l
>
> From reading that, it looks like it should work, and with a plugin
> it does. But with an app it does not, no matter where I put the
> resource or how I address it. I'll confess to being somewhat
> stymied at this point.
>
> Ric
>
>
> On 10/29/08 4:55 PM, in article C52E460B.47F10%riwright@adobe.com,
> "Ric Wright" <riwright@adobe.com> wrote:
>
> Ed,
>
> No, what I do is create a /resource folder in src as peer to
> the packages. Then I address the resource as
> /resource/myimage.gif. Even if I copy it into the bin folder
> it still fails. And the usual method (where it is in
> /resource folder) works fine if it is a plugin, but not if it
> is a Java applet. So I feel that the key has to be in how the
> classloader works differently from a plugin to an applet. But
> I am not expert in classloaders, that's for sure.
>
> Thanks,
> Ric
>
>
>
> On 10/29/08 4:31 PM, in article
> gearpj$pv1$2@build.eclipse.org, "Ed Merks"
> <Ed.Merks@gmail.com> wrote:
>
> Ric,
>
> The resource is in the same package/folder? It's properly
> in the final jar or the bin folder in the right place?
> Does removing the getClassLoader() make a difference.
>
>
> Ric Wright wrote:
>
> Loading resources via Classloader I have a number of
> plugins for various uses. Sometimes I need to load
> resources, such as image files, etc. I usually do it
> via
> MyClass.class.getClassLoader.GetResource(resourceName).
> This works fine in plugins. But if I use this in a
> simple Java app (e.g. With a static main() method) the
> loading of the resource always fails. The classloader
> finds the various classes of the app without problem,
> but can't seem to find the resource.
>
> Is there a good way to do this? Or am I simply
> missing something?
>
> TIA,
> Ric
>
>
>
>
--------------030409070605070506060301
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ric,<br>
<br>
I had a bad feeling about that; recall my asking if removing
getClassLoader() made a difference? I'm not an expert at this black
magic, but if you think about it, lots of classes will share the same
class loader (maybe all of them in a stand-alone application) so you
kind of lose the context when you don't call the method directly on the
class. Sure the class delegates to the class loader, but then the
class calling the class loader is on the class stack, whereas with what
you did, it's not. Likely that makes all the difference between being
able to resolve the path relative to the calling class, or relative to
goodness knows what. So why does it work with Eclipse the way you head
it? Probably because for Eclipse, each bundle has its own class
loader, so the class loader has more context than it does stand
alone. Of course I could be full of hot air too...<br>
<br>
<br>
Ric Wright wrote:
<blockquote cite="mid:C52F4A79.48000%25riwright@adobe.com" type="cite">
<title>Progress - Re: Loading resources via Classloader</title>
<font face="Verdana, Helvetica, Arial"><span style="font-size: 11pt;">Well,
I found a solution, but do not know why it makes a difference. The
solution is that instead of<br>
<br>
this.getClass().getClassLoader().getReso urce(resourceName); <br>
<br>
Use<br>
<br>
this.getClass().getR esource(resourceName); <br>
<br>
The latter works for both plugins and for Java apps. Now the Javadoc
for Class says that getResource delegates the call to its classloader,
so it isn’t clear to me why there would be any difference between the
two. Could some classLoader maven out there cast some light on this?<br>
<br>
TIA, Ric<br>
<br>
On 10/29/08 5:31 PM, in article <a moz-do-not-send="true"
href="C52E4E77.47F1A%riwright@adobe.com">C52E4E77.47F1A%riwright@adobe.com</a>,
"Ric Wright" <<a moz-do-not-send="true" href="riwright@adobe.com">riwright@adobe.com</a>>
wrote:<br>
<br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;">Just to clarify, I am not running an applet,
but a simple Java app, i.e. A class with a static main() method. <br>
<br>
I have done a little more reading, including this article on Sun’s site:<br>
<a moz-do-not-send="true"
href=" http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l"> http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l</a><br>
<br>
From reading that, it looks like it should work, and with a plugin it
does. But with an app it does not, no matter where I put the resource
or how I address it. I’ll confess to being somewhat stymied at this
point.<br>
<br>
Ric<br>
<br>
<br>
On 10/29/08 4:55 PM, in article <a moz-do-not-send="true"
href="C52E460B.47F10%riwright@adobe.com">C52E460B.47F10%riwright@adobe.com</a>,
"Ric Wright" <<a moz-do-not-send="true" href="riwright@adobe.com">riwright@adobe.com</a>>
wrote:<br>
<br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;">Ed,<br>
<br>
No, what I do is create a /resource folder in src as peer to the
packages. Then I address the resource as /resource/myimage.gif. Even
if I copy it into the bin folder it still fails. And the usual method
(where it is in /resource folder) works fine if it is a plugin, but not
if it is a Java applet. So I feel that the key has to be in how the
classloader works differently from a plugin to an applet. But I am not
expert in classloaders, that’s for sure.<br>
<br>
Thanks,<br>
Ric<br>
<br>
<br>
<br>
On 10/29/08 4:31 PM, in article <a moz-do-not-send="true"
href="gearpj$pv1$2@build.eclipse.org">gearpj$pv1$2@build.eclipse.org</a>,
"Ed Merks" <<a moz-do-not-send="true" href="Ed.Merks@gmail.com">Ed.Merks@gmail.com</a>>
wrote:<br>
<br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;">Ric,<br>
<br>
The resource is in the same package/folder? It's properly in the final
jar or the bin folder in the right place? Does removing the
getClassLoader() make a difference.<br>
<br>
<br>
Ric Wright wrote: <br>
</span></font>
<blockquote><font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"> Loading resources via Classloader I have a
number of plugins for various uses. Sometimes I need to load
resources, such as image files, etc. I usually do it via
MyClass.class.getClassLoader.GetResource(resourceName). This works
fine in plugins. But if I use this in a simple Java app (e.g. With a
static main() method) the loading of the resource always fails. The
classloader finds the various classes of the app without problem, but
can’t seem to find the resource.<br>
<br>
Is there a good way to do this? Or am I simply missing something?<br>
<br>
TIA,<br>
Ric <br>
</span></font></blockquote>
<font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"><br>
</span></font></blockquote>
<font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"><br>
</span></font></blockquote>
<font face="Verdana, Helvetica, Arial"><span
style="font-size: 11pt;"><br>
</span></font></blockquote>
</blockquote>
</body>
</html>
--------------030409070605070506060301--
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Progress - Re: Loading resources via Classloader [message #265969 is a reply to message #265965] |
Thu, 30 October 2008 21:21 |
Eclipse User |
|
|
|
Originally posted by: riwright.adobe.com
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3308221292_197717
Content-type: text/plain;
charset="ISO-8859-1"
Content-transfer-encoding: 8bit
Thanks, Ed. That seems to make sense to me, but like you, I regard the
whole area of class-loaders as black magic. But the good news is that it
works. These annoying little problems always vex me because I can find a
workaround, but the fact that something that
|
|
|
Re: Progress - Re: Loading resources via Classloader [message #265976 is a reply to message #265969] |
Fri, 31 October 2008 08:00 |
Danail Nachev Messages: 110 Registered: July 2009 |
Senior Member |
|
|
Hi Ric,
The problem is the way URL are constructed by JDK's URLClassLoader. If
your jar/folder is located in the filesystem, then its base URL is:
file://some folder/bin
When you pass /resources/image.gif, the resulting URL for your resource is:
file:/resources/image.gif
because it is absolute.
Equinox (bundle classloader) resolve all paths relative to the bundle root.
The reason why Class.getResource() works, is because it is specified as
relative to the class instead of relative to the classpath root.
BR,
Danail
Ric Wright wrote:
> Thanks, Ed. That seems to make sense to me, but like you, I regard the
> whole area of class-loaders as black magic. But the good news is that
> it works. These annoying little problems always vex me because I can
> find a workaround, but the fact that something that “should work” keeps
> dragging me back to it.
>
> Ric
>
>
>
> On 10/30/08 11:46 AM, in article gecvdi$6sr$1@build.eclipse.org, "Ed
> Merks" <Ed.Merks@gmail.com> wrote:
>
> Ric,
>
> I had a bad feeling about that; recall my asking if removing
> getClassLoader() made a difference? I'm not an expert at this black
> magic, but if you think about it, lots of classes will share the
> same class loader (maybe all of them in a stand-alone application)
> so you kind of lose the context when you don't call the method
> directly on the class. Sure the class delegates to the class
> loader, but then the class calling the class loader is on the class
> stack, whereas with what you did, it's not. Likely that makes all
> the difference between being able to resolve the path relative to
> the calling class, or relative to goodness knows what. So why does
> it work with Eclipse the way you head it? Probably because for
> Eclipse, each bundle has its own class loader, so the class loader
> has more context than it does stand alone. Of course I could be
> full of hot air too...
>
>
> Ric Wright wrote:
>
> Progress - Re: Loading resources via Classloader Well, I found a
> solution, but do not know why it makes a difference. The
> solution is that instead of
>
> this.getClass().getClassLoader().getResource(resourceName);
>
> Use
>
> this.getClass().getResource(resourceName);
>
> The latter works for both plugins and for Java apps. Now the
> Javadoc for Class says that getResource delegates the call to
> its classloader, so it isn’t clear to me why there would be any
> difference between the two. Could some classLoader maven out
> there cast some light on this?
>
> TIA, Ric
>
> On 10/29/08 5:31 PM, in article
> C52E4E77.47F1A%riwright@adobe.com, "Ric Wright"
> <riwright@adobe.com> wrote:
>
>
>
> Just to clarify, I am not running an applet, but a simple
> Java app, i.e. A class with a static main() method.
>
> I have done a little more reading, including this article on
> Sun’s site:
> http://java.sun.com/j2se/1.5.0/docs/guide/lang/resources.htm l
>
> From reading that, it looks like it should work, and with a
> plugin it does. But with an app it does not, no matter
> where I put the resource or how I address it. I’ll confess
> to being somewhat stymied at this point.
>
> Ric
>
>
> On 10/29/08 4:55 PM, in article
> C52E460B.47F10%riwright@adobe.com, "Ric Wright"
> <riwright@adobe.com> wrote:
>
>
>
> Ed,
>
> No, what I do is create a /resource folder in src as
> peer to the packages. Then I address the resource as
> /resource/myimage.gif. Even if I copy it into the bin
> folder it still fails. And the usual method (where it
> is in /resource folder) works fine if it is a plugin,
> but not if it is a Java applet. So I feel that the key
> has to be in how the classloader works differently from
> a plugin to an applet. But I am not expert in
> classloaders, that’s for sure.
>
> Thanks,
> Ric
>
>
>
> On 10/29/08 4:31 PM, in article
> gearpj$pv1$2@build.eclipse.org, "Ed Merks"
> <Ed.Merks@gmail.com> wrote:
>
>
>
> Ric,
>
> The resource is in the same package/folder? It's
> properly in the final jar or the bin folder in the
> right place? Does removing the getClassLoader()
> make a difference.
>
>
> Ric Wright wrote:
>
>
> Loading resources via Classloader I have a
> number of plugins for various uses. Sometimes I
> need to load resources, such as image files,
> etc. I usually do it via
> MyClass.class.getClassLoader.GetResource(resourceName).
> This works fine in plugins. But if I use this
> in a simple Java app (e.g. With a static main()
> method) the loading of the resource always
> fails. The classloader finds the various
> classes of the app without problem, but can’t
> seem to find the resource.
>
> Is there a good way to do this? Or am I simply
> missing something?
>
> TIA,
> Ric
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
Goto Forum:
Current Time: Wed Feb 05 09:42:07 GMT 2025
Powered by FUDForum. Page generated in 0.09161 seconds
|