3

I want to include some binary not Java-related files in my Eclipse plugin, so I can access them later from within the Java code of the plugin.

1) As far as I understand I can add some files and folders to include in a build in the "Build / Binary Build" section of the Build Configuration:

enter image description here

Unfortunately the folder "folder-to-include" and all files beneath are not copied to the "bin" folder (or anywhere else) after building the plugin. Did I misunderstand that dialog? I always thought of the "bin" folder as the "root" of the built project / plugin. What is the proper way to include binary files in the build?

2) If I managed to include my files in the built plugin, how do I determine the path to them so I can open and work with them in one of the Java classes of the plugin?

2
  • How are you building the plug-in? Everything you check should be included at the top level of the jar. Also you don't have plugin.xml checked - which is an important file.
    – greg-449
    Feb 16, 2014 at 21:32
  • @greg-449 I use the builtin "build project" functionality which compiles all Java files to .class ones and copy them together with some plugin metadata to the bin folder (this is how it looks for me).
    – muffel
    Feb 17, 2014 at 6:57

1 Answer 1

3

Everything you check in the build should be included in the plug-in jar at the top level (the bin directory is handled specially).

To find an object in a plug-in use:

URL url = FileLocator.find(bundle, new Path(path), null);

where path is a relative path in the plug-in and bundle is the plug-in Bundle. You can get the Bundle from the BundleContext passed to the plug-in activator or by using Platform.getBundle("plugin id")

The URL returned from this will use the bundle scheme, to convert it to a file URL use:

URL fileURL = FileLocator.toFileURL(url);

The file URL returned may be in a temporary location.

Update: When you run your plug-in from with Eclipse (with Run / Eclipse Application) then no jar is built and the folders are not copied anywhere. You still use the FileLocator API to access the folders and the paths are the same.

2
  • Thank you for your answer. Unfortunately no jar is built at all if I build or run/debug my plugin. Do I have to bundle my plugin within a JAR to have the files copied? Afaik I do not have to build a jar from my plugin in order to use it - just as it doesn't build one when running/debugging it.
    – muffel
    Feb 17, 2014 at 6:56
  • Updated answer with details about running during testing in Eclipse
    – greg-449
    Feb 17, 2014 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.