this is not really a problem I have, but more a question about good practice.
I want to resolve a URL of a File of my eclipse plugin, but there are many ways which work. I could not find anything about which one should be preferred.
First of all: how should I obtain my bundle? Through the Activator or the Platform?
Bundle bundle = Platform.getBundle("my.bundle.id");
or
Bundle bundle = Activator.getDefault().getBundle();
The other question is how to get the url. Either with
URL url = FileLocator.find(bundle, new Path("folder/file.txt"), null);
or
URL url = bundle.getEntry("folder/file.txt");
All of this works, but which way is the best? Does it even make a difference?
No it doesn’t make any difference (actually
FileLocatorusesbundle.getEntry). The advantage is of usingbundle.getEntryis that you don’t have a dependency to an eclipse-bundle; I don’t know if that fact is relevant for you.I’m always using the
FileLocatormethod in RCPs but using theopenStreammethod to read the contents of files within bundles.