eclipseeclipse-plugineclipse-rcpnodeclipse

Eclipse plugin dev: make bundle to explode inside `plugins` folder


There is old Eclipse Image Viewer plugin https://github.com/persal/quickimage that I want to update.

After adding maven/tycho build and building against Kepler.

It works in new Eclipse instance (project -> run as Eclipse application), but when installing here is an issue #6

org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: file:\D:\Progs\Eclipses\eclipse-standard-luna-R-win32-x86_64\eclipse\plugins\nu.psnet.quickimage.plugin_1.1.0.201503030326.jar!\icons\previous.gif (The filename, directory name, or volume label syntax is incorrect.))

文件名、目录名或卷标语法不正确

Looking at the code there is line

iconsdir = FileLocator.resolve(QuickImagePlugin.getDefault().getBundle().getEntry("/")).getFile() + "icons" + File.separator;

that gets path like that.

The problem is that should work if the bungle jar becomes folder like nu.psnet.quickimage_1.0.3.2

UPDATE: As IDE using Luna 4.4.0


Solution

  • If you can change the source of the plugin you can change

    iconsdir = FileLocator.resolve(QuickImagePlugin.getDefault().getBundle().getEntry("/")).getFile() + "icons" + File.separator;
    

    to something like:

    URL dir = FileLocator.find(QuickImagePlugin.getDefault().getBundle(),
                               new Path("icons"), null);
    
    dir = FileLocator.toFileURL(dir);
    
    String iconsdir = dir.getPath() + File.separator;
    

    This should work even when the plugin is packaged in a jar.