Eclipse plugin: Accessing files bundles with the plugin

If you've got a plugin, you often want to access text files, or whatever, bundled with that plugin.

This provides the answer:

  1. Make a /files/ directory in your plugin's base directory.

  2. Use this method

     public static String getFileFromBundle(String fileName) {
     	try {
     		URL url = new URL( "platform:/plugin/ITS_SYMBLOIC_NAME/files/"+fileName);
     		InputStream inputStream = url.openConnection().getInputStream();
     		BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
     		String inputLine, total="";
     		while ((inputLine = in.readLine()) != null) {
     			total = total + inputLine + "\n";
     		return total;
     	} catch (IOException e) {
     		return null;

The SYMBOLIC-NAME above refers to the values in the META-INF/MANIFEST.MF file:

    Bundle-SymbolicName: ITS_SYMBLOIC_NAME;singleton:=true
eclipse eclipse-plugin

Edit on github
comments powered by Disqus
Click me