relative path in jar file

Hi there.
I have created a plugin and placed the content in a jar file.
The structure is like this:

com/intellij/openapi/modification/ META-INF/plugin.xml resources/icons/<*.png>]]>

My question is how do i get the icons image files using the relative path. I have tried loading them using the path "resources/icons/icon.png" but it doen't work.
I know this is more a Java question but can anybody give me a hint? For what i have found so far i think i should use the ClassLoaded.getResource() method but i still can't make it work.

Raul

0
Avatar
Permanently deleted user

.getClass().getResource("/resources/icons/<*.png>") or .class.getResource("/resources/icons/<*.png>]]>")

0
Avatar
Permanently deleted user

Chris Sherratt wrote:

<this>.getClass().getResource("/resources/icons/<*.png>")


That isn't cool, a subclass might have been loaded with a different
classloader.

or

<clazz>.class.getResource("/resources/icons/<*.png>")


This is better.

0
Avatar
Permanently deleted user

Thanks guys.
I tried both of them and they work.
Can you just explain why is the second one better?

0

请先登录再写评论。