I'm relatively new to developing Eclipse plugins and have a couple of files in src/resources
that I'm trying to reference in the plugin I'm making currently. However, I can't seem to figure it out.
I've attempted the following methods to retrieve the resources:
MyClass.class.getResourceAsStream("/file_name")
MyClass.class.getResourceAsStream("/resources/file_name")
MyClass.class.getResourceAsStream("resources/file_name")
Bundle bundle = ResourcesPlugin.getPlugin.getBundle();
URL url = FileLocator.find(bundle, new Path("/resources/file_name") )
InputStream is = url.openStream();
...
Bundle bundle = ResourcesPlugin.getPlugin.getBundle();
URL url = FileLocator.find(bundle, new Path("resources/file_name") )
InputStream is = url.openStream();
...
None have worked, and I can't think of a quick way to determine what exception is being thrown and/or where it's being thrown from.
I'm not sure if it has any relevance, but the path for the plugin icon in the toolbar is /resources/<icon>
. I suspect that image loading is different than resource loading, though.
Any thoughts as to where I might be going wrong with this?
So, I wound up solving this, but the problem was an interesting one. One of the resources that I was trying to reference was a .java
file, and that .java
file was being compiled and thus no longer existed in the resulting JAR. Changing the extension to .txt
got me around this.
That said, I did need to change the path I was using in MyClass.class.getResourceAsStream
to ../../resources/file.txt
, as per howgler's answer.