Read a resource inside a plugin JAR

93 views
Skip to first unread message

Antonio Manuel Muñiz Martín

unread,
Dec 28, 2011, 2:08:26 PM12/28/11
to js...@googlegroups.com
Hello,

I'm using JSPF in an Open Source project
(http://clinker.klicap.es/projects/opina). Congrats for this great
product.
All management related to plugins in Opina is working fine, but at
this time I have the need to load (as InputStream) a resource which
lives inside the plugin JAR, it is a CSS file located at the root of
the plugin JAR file.
I tried to do it myself but didn't find any way. Am I missing something?

Thanks,
Antonio.

--
Antonio Manuel Muñiz Martín
Software Developer at klicap - ingeniería del puzle

work phone + 34 954 894 322
www.klicap.es | blog.klicap.es

Antonio Manuel Muñiz Martín

unread,
Dec 28, 2011, 4:43:54 PM12/28/11
to js...@googlegroups.com
Hi,

I'm getting this working by using the plugin object classloader:

InputStream is =
plugin.getClass().getClassLoader().getResourceAsStream("es/klicap/opina/plugin/default-theme.css");

I hope it will be helpful for others.
Antonio.

2011/12/28 Antonio Manuel Muñiz Martín <amu...@klicap.es>:

Rick Herrick

unread,
Dec 28, 2011, 6:12:03 PM12/28/11
to js...@googlegroups.com
Antonio,

That's pretty close to how I'm doing it. I have a situation where I may end up with lots of plugins that contain their own resources of various sorts, e.g. CSS, Velocity templates, JSP files, etc. I created a resource tag structure where you can query the plugin itself for its resources. Then I created a PluginResourceLoader that extends the standard Java ResourceLoader and configure that for whatever engine is loading the resources. For example, the Velocity engine takes a property called plugin.resource.loader.class, which I set to my PluginResourceLoader. That takes resource IDs in the form:

plugin:PluginName:ResourceName

So, e.g.:

plugin:YourPlugin:es/klicap/opina/plugin/default-theme.css

That creates a URLClassLoader from the URL for the plugin jar file and loads the resource by path.

In the end though I'm doing exactly the same thing as you're describing, it's just that I'm scoping the resource load to the particular resource for the plugin.

Antonio Manuel Muñiz Martín

unread,
Dec 30, 2011, 3:56:09 AM12/30/11
to js...@googlegroups.com
Thanks for your point Rick.
In my case, I want to load resources which lives in plugins classpath,
I don't care in which plugin (JAR) it lives, in fact, this behaviour
is great, so I can "share" resources between plugins.

Antonio.

2011/12/29 Rick Herrick <rher...@gmail.com>:

--

Rick Herrick

unread,
Jan 1, 2012, 4:52:53 PM1/1/12
to js...@googlegroups.com
Right, that makes sense. We're specifically trying to cut down on sharing in that regard, so that we don't have to worry about different plugins having resources with the same name and hiding each others' resources, e.g. foo.vm existing in two different jars. Because of the nature of the business domain in our case (medical imaging), it's quite likely that two separate plugins would have, e.g. session.vm or dicom.vm. In the end, though, the solution is exactly the same, it's just the route you take to get there :)

Antonio Manuel Muñiz Martín

unread,
May 22, 2012, 7:24:26 AM5/22/12
to js...@googlegroups.com
Hi Rick,

Is this development open source? I would like to take a look.

Thanks,
Antonio.

2011/12/29 Rick Herrick <rher...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages