使用eclipse API读取eclipse安装路径

时间:2009-03-24 06:29:06

标签: java eclipse-pde

我打开了eclipse 3.3.2。现在我需要获得当前的eclispe安装路径。是

有没有eclipse API来获取eclipse安装路径?请帮忙。

先谢谢..

Snehal

2 个答案:

答案 0 :(得分:6)

自eclipse3.4和p2 mechanism以来,您可以使用代表网址的org.eclipse.osgi.service.datalocation.Location

该接口包含** ECLIPSE_HOME_FILTER**,这是一个常量,用于定义用于获取指定eclipse home位置的服务的过滤字符串(即“eclipse.home.location”。)

但是在eclipse3.3中,只需查询属性值“eclipse.home.location”,如下所示:

System.getProperty("eclipse.home.location");

答案 1 :(得分:5)

为什么需要安装路径有点疑问。您的代码(插件)不应该依赖于安装目录中的任何内容。如果您正在考虑写入安装目录。别!你无法在共享安装中做到这一点,无论如何这都是一个非常糟糕的主意。

如果您需要访问插件中的文件,您只需使用以下代码:

Activator.getDefault().getBundle().getEntry(fileName);

获取用户工作空间的位置

Platform.getInstanceLocation().getURL().getPath();