Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Loading resources with getResource
Loading resources with getResource [message #332583] Wed, 29 October 2008 22:40 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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. &nbsp;Sometimes I need to load
resources, such as image files, etc. &nbsp;I usually do it via
MyClass.class.getClassLoader.GetResource(resourceName). &nbsp;This works
fine in plugins. &nbsp;But if I &nbsp;use this in a simple Java app (e.g. With a
static main() method) the loading of the resource always fails. &nbsp;The
classloader finds the various classes of the app without problem, but
can&#8217;t seem to find the resource.<br>
<br>
Is there &nbsp;a good way to do this? &nbsp;Or am I simply missing something?<br>
<br>
TIA,<br>
Ric<br>
</span></font>
</blockquote>
</body>
</html>

--------------020400090909090901030204--
Re: Loading resources with getResource [message #332586 is a reply to message #332584] Thu, 30 October 2008 01:54 Go to previous messageGo to next message
Raja Kannappan is currently offline Raja KannappanFriend
Messages: 24
Registered: July 2009
Junior Member
Try MyClass.class.getResource(String resourceName) and make sure resource
is on your classpath.
Re: Loading resources with getResource [message #332599 is a reply to message #332586] Thu, 30 October 2008 14:46 Go to previous message
Eclipse UserFriend
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
Previous Topic:Update/Install problems - Is this the right forum?
Next Topic:Installation error: An error occurred during provisioning
Goto Forum:
  


Current Time: Fri Feb 07 09:36:43 GMT 2025

Powered by FUDForum. Page generated in 0.25343 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top