Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Plugin resources not found
Plugin resources not found [message #290381] Wed, 24 August 2005 18:26 Go to next message
Eclipse UserFriend
Originally posted by: plesner.quenta.org

I'm developing an eclipse plugin that for a library I've written, and I'm
having some trouble getting the plugin to locate my .properties resources.
The plugin and the library are two separate eclipse projects and the
library contains a bunch of .properties files. When I run the plugin, I
have no trouble using classes from the library, but I get a
MissingResourceException as soon as any library class tries try to load a
properties file. If I run a class as a java application that uses the
same classes and resources there are no problems. Does anyone know how to
fix this or what I might be doing wrong?

I'm using Eclipse 3.1.0; the code is available from
http://sourceforge.net/projects/tedir


Thanks,
Christian
Re: Plugin resources not found [message #290385 is a reply to message #290381] Wed, 24 August 2005 18:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Christian Plesner Hansen" <plesner@quenta.org> wrote in message
news:60837a867b74b92ccf5ec64d2ae1c117$1@www.eclipse.org...
> I'm developing an eclipse plugin that for a library I've written, and I'm
> having some trouble getting the plugin to locate my .properties resources.
> The plugin and the library are two separate eclipse projects and the
> library contains a bunch of .properties files. When I run the plugin, I
> have no trouble using classes from the library, but I get a
> MissingResourceException as soon as any library class tries try to load a
> properties file. If I run a class as a java application that uses the
> same classes and resources there are no problems. Does anyone know how to
> fix this or what I might be doing wrong?
>
> I'm using Eclipse 3.1.0; the code is available from
> http://sourceforge.net/projects/tedir
>
>
Where is it failing in the code? Do you have a snippet you can share?
---
Sunil
Re: Plugin resources not found [message #290395 is a reply to message #290385] Wed, 24 August 2005 20:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: plesner.quenta.org

The problem occurs when loading a resource bundle[1]:

public MessageFactory(final String baseName) {
this.resources = ResourceBundle.getBundle(baseName);
}

The first use of this in a static initializer[2]:

private static final MessageFactory FACTORY = new MessageFactory(PATH +
"/messages");

This code works just fine when used from a simple java application but not
when used by a plugin.


-- Christian

[2]:
http://cvs.sourceforge.net/viewcvs.py/tedir/org.quenta.tedir .antonius/src/org/quenta/tedir/antonius/message/MessageFacto ry.java?rev=1.1&view=markup
[1]:
http://cvs.sourceforge.net/viewcvs.py/tedir/org.quenta.tedir .hadrian/src/org/quenta/tedir/hadrian/lex/Package.java?rev=1 .2&view=markup

> "Christian Plesner Hansen" <plesner@quenta.org> wrote in message
> news:60837a867b74b92ccf5ec64d2ae1c117$1@www.eclipse.org...
>> I'm developing an eclipse plugin that for a library I've written, and I'm
>> having some trouble getting the plugin to locate my .properties resources.
>> The plugin and the library are two separate eclipse projects and the
>> library contains a bunch of .properties files. When I run the plugin, I
>> have no trouble using classes from the library, but I get a
>> MissingResourceException as soon as any library class tries try to load a
>> properties file. If I run a class as a java application that uses the
>> same classes and resources there are no problems. Does anyone know how to
>> fix this or what I might be doing wrong?
>>
>> I'm using Eclipse 3.1.0; the code is available from
>> http://sourceforge.net/projects/tedir
>>
>>
> Where is it failing in the code? Do you have a snippet you can share?
> ---
> Sunil
Re: Plugin resources not found [message #290396 is a reply to message #290395] Wed, 24 August 2005 21:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Christian Plesner Hansen" <plesner@quenta.org> wrote in message
news:34a320c208fa0cae99cf1d7365658d01$1@www.eclipse.org...
> The problem occurs when loading a resource bundle[1]:
>
> public MessageFactory(final String baseName) {
> this.resources = ResourceBundle.getBundle(baseName);
> }
>
> The first use of this in a static initializer[2]:
>
> private static final MessageFactory FACTORY = new MessageFactory(PATH +
> "/messages");
>
> This code works just fine when used from a simple java application but not
> when used by a plugin.
>
>

Did you try it without replacing the '.' with '/'?
i.e.,
public static final String PATH = Package.class.getPackage().getName();
private static final MessageFactory FACTORY = new MessageFactory(PATH +
".messages");

That's how I do it in my plugin and it always works.
---
Sunil
Re: Plugin resources not found [message #290652 is a reply to message #290396] Mon, 29 August 2005 12:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: plesner.oovm.com

I've tried various combinations of dots and slashes and it doesn't work.
I don't think the name of the resource is the problem; if it was, I
wouldn't expect the code to work when run as a standard java application.

Sunil Kamath wrote:
> "Christian Plesner Hansen" <plesner@quenta.org> wrote in message
> news:34a320c208fa0cae99cf1d7365658d01$1@www.eclipse.org...
>
>>The problem occurs when loading a resource bundle[1]:
>>
>> public MessageFactory(final String baseName) {
>> this.resources = ResourceBundle.getBundle(baseName);
>> }
>>
>>The first use of this in a static initializer[2]:
>>
>> private static final MessageFactory FACTORY = new MessageFactory(PATH +
>>"/messages");
>>
>>This code works just fine when used from a simple java application but not
>>when used by a plugin.
>>
>>
>
>
> Did you try it without replacing the '.' with '/'?
> i.e.,
> public static final String PATH = Package.class.getPackage().getName();
> private static final MessageFactory FACTORY = new MessageFactory(PATH +
> ".messages");
>
> That's how I do it in my plugin and it always works.
> ---
> Sunil
>
>
Re: Plugin resources not found [message #291226 is a reply to message #290652] Mon, 12 September 2005 16:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: plesner.quenta.org

I have finally figured out what the problem was and so, in case someone
experiences the same thing and stumbles upon this thread, here's what
was wrong.

The setup is this: I have a parser library, hadrian, which has an
associated eclipse plugin, hadrian.eclipse. Hadrian itself uses another
library, antonius. Hadrian contains a resource, messages.properties,
which is used by an instance of the class MessageFactory.
MessageFactory is defined in antonius, and an instance is created giving
the path of the resource:

x = new MessageFactory(".../hadrian/messages.properties")

and then the message factory loads the resource using
MessageBundle.getBundle(String). Running the code as a regular java
application works, running it through the hadrian.eclipse plugin
doesn't: the resource cannot be found.

The problem turns out to be that you don't just load a resource, you
load it through a specific class loader. In this case, since the
getBundle(String) is used in MessageFactory, the classloader used is
MessageFactory's. When running a java application there is just one
class loader for all classes, so the classloader used for MessageFactory
is also the one used to load classes and resources from hadrian so it
has no problem finding the resource. When running a plugin, however,
there are _separate_ classloaders for each plugin. So the classloader
used to load classes for antonius has no way of finding the resource
because it is in a plugin is knows nothing about. Reasonable enough,
really, but pretty tough to figure out if you don't know what you're
looking for!

The solution, in my case, was to ensure that the resource bundle is
loaded in a class in hadrian:

x = new MessageFactory(MessageBundle.getBundle("..."))


-- Christian

Christian Plesner Hansen wrote:
> I've tried various combinations of dots and slashes and it doesn't work.
> I don't think the name of the resource is the problem; if it was, I
> wouldn't expect the code to work when run as a standard java application.
>
> Sunil Kamath wrote:
>
>> "Christian Plesner Hansen" <plesner@quenta.org> wrote in message
>> news:34a320c208fa0cae99cf1d7365658d01$1@www.eclipse.org...
>>
>>> The problem occurs when loading a resource bundle[1]:
>>>
>>> public MessageFactory(final String baseName) {
>>> this.resources = ResourceBundle.getBundle(baseName);
>>> }
>>>
>>> The first use of this in a static initializer[2]:
>>>
>>> private static final MessageFactory FACTORY = new MessageFactory(PATH
>>> + "/messages");
>>>
>>> This code works just fine when used from a simple java application
>>> but not when used by a plugin.
>>>
>>>
>>
>>
>> Did you try it without replacing the '.' with '/'?
>> i.e.,
>> public static final String PATH = Package.class.getPackage().getName();
>> private static final MessageFactory FACTORY = new
>> MessageFactory(PATH + ".messages");
>>
>> That's how I do it in my plugin and it always works.
>> ---
>> Sunil
>>
>>
Re: Plugin resources not found [message #291232 is a reply to message #291226] Mon, 12 September 2005 17:59 Go to previous message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"Christian Plesner Hansen" <plesner@quenta.org> wrote in message
news:dg4a56$fj8$1@news.eclipse.org...
>
> [snip]
>
> The problem turns out to be that you don't just load a resource, you load
> it through a specific class loader. In this case, since the
> getBundle(String) is used in MessageFactory, the classloader used is
> MessageFactory's. When running a java application there is just one class
> loader for all classes, so the classloader used for MessageFactory is also
> the one used to load classes and resources from hadrian so it has no
> problem finding the resource. When running a plugin, however, there are
> _separate_ classloaders for each plugin. So the classloader used to load
> classes for antonius has no way of finding the resource because it is in a
> plugin is knows nothing about. Reasonable enough, really, but pretty
> tough to figure out if you don't know what you're looking for!
>
Ah, you didn't make it clear the first time that your library was a separate
plugin.
I was under the impression that it was just another jar file.
Otherwise, perhaps you would have gotten your answer sooner since I ran into
the same issue a couple of months ago.
---
Sunil
Previous Topic:AntRunner and BuildLogger
Next Topic:Programmatically setting javadoc location
Goto Forum:
  


Current Time: Thu Apr 25 06:32:55 GMT 2024

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

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

Back to the top