timk
timk

Reputation: 97

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 anybody know API to get this path? I am not looking for a resource in a plugin but eclipse.exe itself.

Thanks.

Upvotes: 4

Views: 2400

Answers (2)

driedler
driedler

Reputation: 4190

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

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

Upvotes: 2

Kane
Kane

Reputation: 8172

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)

Upvotes: 2

Related Questions