【发布时间】:2011-09-28 12:08:08
【问题描述】:
在我的 Eclipse 插件 (A) 中,我需要以编程方式获取运行插件 (A) 的 eclipse.exe 的路径。
有人知道获取此路径的 API 吗?我不是在插件中寻找资源,而是在 eclipse.exe 本身。
谢谢。
【问题讨论】:
标签: eclipse plugins path executable
在我的 Eclipse 插件 (A) 中,我需要以编程方式获取运行插件 (A) 的 eclipse.exe 的路径。
有人知道获取此路径的 API 吗?我不是在插件中寻找资源,而是在 eclipse.exe 本身。
谢谢。
【问题讨论】:
标签: eclipse plugins path executable
试试下面的代码:
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)
【讨论】:
这是 Andrew Niefer 在上述答案中的评论,更简单:
String eclipseExecutablePath = System.getProperty("eclipse.launcher");
System.out.println(eclipseExecutablePath);
【讨论】: