gpt4 book ai didi

eclipse - 以编程方式查找eclipse安装目录

转载 作者:行者123 更新时间:2023-12-02 14:14:53 24 4
gpt4 key购买 nike

在我的 eclipse 插件(A) 中,我需要以编程方式获取运行插件(A) 的 eclipse.exe 的路径。

有人知道 API 可以获取此路径吗?我不是在插件中寻找资源,而是在 eclipse.exe 本身中寻找资源。

谢谢。

最佳答案

尝试下面的代码:

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)

关于eclipse - 以编程方式查找eclipse安装目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6577898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com