Loading resources with getResource [message #332583] |
Wed, 29 October 2008 22:40  |
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_3308139653_18446993
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 with getResource [message #332584 is a reply to message #332583] |
Wed, 29 October 2008 23:32   |
Eclipse User |
|
|
|
This is a multi-part message in MIME format.
--------------020400090909090901030204
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ric,
Please don't cross post the same question to multiple newsgroups.
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
--------------020400090909090901030204
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>
Please don't cross post the same question to multiple newsgroups.<br>
<br>
<br>
Ric Wright wrote:
<blockquote cite="mid:C52E3485.47EF6%25riwright@adobe.com" type="cite">
<title>Loading resources with getResource</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<br>
</span></font>
</blockquote>
</body>
</html>
--------------020400090909090901030204--
|
|
|
|
Re: Loading resources with getResource [message #332599 is a reply to message #332586] |
Thu, 30 October 2008 14:46  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
By the way, be careful with the resource name here.
If you don't put in a leading slash then it will automatically prefix
the name with package name of the class.
For example:
package x.y.z;
public class MyClass {
public void somemethod() {
URI url = MyClass.class.getResource("abc.txt");
}
}
In this case, it will actually look for the resource "/x/y/z/abc.txt".
In other words if it is a relative path it will look in the directory
where MyClass is found.
If you knew exactly where it was at then you should use "/abc.txt" instead.
This has tripped me up many times. :-)
Raja Kannappan wrote:
> Try MyClass.class.getResource(String resourceName) and make sure
> resource is on your classpath.
>
--
Thanks,
Rich Kulp
|
|
|
Powered by
FUDForum. Page generated in 0.25343 seconds