John Smith
John Smith

Reputation: 787

Find resources in project tree

I have a plugin project and I need a method that will find and open a file in the project where the plugin will run. I have in a variable the name of the file which should be inside the project. How can this be done ?

Thank you !

Upvotes: 0

Views: 37

Answers (1)

ratiaris
ratiaris

Reputation: 325

For a file resource inside a plug-in:

    Bundle bundle = Activator.getDefault().getBundle("com.your.plugin.name");
    if (bundle != null) {
        URL fileURL;
        try {
            fileURL = FileLocator.toFileURL(bundle.getEntry("/path/to/your/file/from/the/plugin/root"));
            String fileSystemPathToYourFile = fileURL.getPath());
        } catch (IOException exception) {
            // ...
        }
    }

Of course, you'll have to make sure the corresponding resource is properly included in your plug-in's binary build (bin.include property in build.properties file, or Binary Build section in the Build tab of the plug-in manifest editor).

If your file is a JAR, you may also have to export your plug-in as a directory (not 100% sure, may depend of what you actually do with your JAR resource - like add it to a project's build path or to a launch configuration classpath).

Upvotes: 1

Related Questions