Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include and access binary (non-Java) files in an Eclipse plugin

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?

like image 657
muffel Avatar asked Feb 26 '26 11:02

muffel


1 Answers

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.

like image 169
greg-449 Avatar answered Feb 28 '26 01:02

greg-449



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!