开发者

Programmatically find eclipse installation directory

In my eclipse plugin(A), I need to programmatically get a path to eclipse.exe, which runs the plugin(A).

Does a开发者_如何学Gonybody know API to get this path? I am not looking for a resource in a plugin but eclipse.exe itself.

Thanks.


Try below code:

import org.eclipse.osgi.service.datalocation.Location;

public <T> T getService(Class<T> clazz, String filter) {
        BundleContext context = getBundle().getBundleContext();
        ServiceTracker tracker = null;
        try{ 
            tracker = new ServiceTracker(context, context.createFilter("(&(" + Constants.OBJECTCLASS + "=" + clazz.getName()  //$NON-NLS-1$ //$NON-NLS-2$
                    + ")" + filter + ")"), null); //$NON-NLS-1$ //$NON-NLS-2$
            tracker.open();
            return (T) tracker.getService();
        } catch (InvalidSyntaxException e) {
            return null;
        } finally {
            if(tracker != null)
                tracker.close();
        }
    }

getService(Location.class, Location.INSTALL_FILTER)


This was a comment in the answer above by Andrew Niefer, much simplier:

String eclipseExecutablePath = System.getProperty("eclipse.launcher");
System.out.println(eclipseExecutablePath);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜