问题
Does anyone know how to get a file with uri from a self-made Eclipse Plug-in?
Absolute paths would be no problem:
URI.createFileURI("C:/Users/hp/workspace(dke)/SMartGen/StarSchema.profile.uml");
But how do I access local resources relatively?
URI.createFileURI("jar:file:/%ECLIPSE_HOME%/plugins/SMartGen.jar!StarSchema.profile.uml");
doesn't work this way....
Happy for every answer.
lg martin
回答1:
Use the FileLocator.
Example:
URL iconUrl = FileLocator.find(Platform.getBundle("myBundle"), new Path("icons/someIcon.png"), null);
This will get the URL of a file "someIcon.png" that is located in the "icons" folder in the bundle "myBundle".
回答2:
For getting a resource out of eclipse, you can use org.osgi.framework.Bundle.getEntry(String)
. That returns a standard java.net.URL
, which can also be used to get the InputStream
for consumption. It has the advantage of not caring if your plugin is in directory form, jar form, or in your workspace.
Bundle bundle = FrameworkUtil.getBundle(MyClass.class);
URL url = bundle.getEntry("StarSchema.profile.uml");
URL has a handy toURI()
method as well.
来源:https://stackoverflow.com/questions/6253886/access-relative-path-from-eclipse-plugin