问题 如何获取Eclipse安装目录的绝对路径?


我正在编写一个由插件组成的Eclipse产品。
在我的一个插件中,我需要获取安装Eclipse的目录的绝对路径。
(即 /Applications/Eclipse 在Mac或 C:\Program Files\Eclipse 在胜利)。

无法为此找到API。想法?


5370
2017-12-20 22:18


起源



答案:


codejammer 建议:

以下为您提供安装位置

Platform.getInstallLocation().getURL()

org.eclipse.core.runtime.Platform API

/**
 * Returns the location of the base installation for the running platform
 * <code>null</code> is returned if the platform is running without a configuration location.
 * <p>
 * This method is equivalent to acquiring the <code>org.eclipse.osgi.service.datalocation.Location</code>
 * service with the property "type" equal to {@link Location#INSTALL_FILTER}.
 *</p>
 * @return the location of the platform's installation area or <code>null</code> if none
 * @since 3.0
 * @see Location#INSTALL_FILTER
 */

11
2017-12-20 22:25



getInstanceLocation似乎提供了当前的eclipse工作空间,奇怪的是。但是Platform.getInstallLocation()。getURL()提供了我所需要的东西,我通过探索其余的Platform方法找到了它。谢谢! - wildabeast
应删除上述答案的第一部分。 “实例位置”只是“工作空间”的另一个名称,而这不是所要求的。第二部分是正确的答案。 - alphakermit


答案:


codejammer 建议:

以下为您提供安装位置

Platform.getInstallLocation().getURL()

org.eclipse.core.runtime.Platform API

/**
 * Returns the location of the base installation for the running platform
 * <code>null</code> is returned if the platform is running without a configuration location.
 * <p>
 * This method is equivalent to acquiring the <code>org.eclipse.osgi.service.datalocation.Location</code>
 * service with the property "type" equal to {@link Location#INSTALL_FILTER}.
 *</p>
 * @return the location of the platform's installation area or <code>null</code> if none
 * @since 3.0
 * @see Location#INSTALL_FILTER
 */

11
2017-12-20 22:25



getInstanceLocation似乎提供了当前的eclipse工作空间,奇怪的是。但是Platform.getInstallLocation()。getURL()提供了我所需要的东西,我通过探索其余的Platform方法找到了它。谢谢! - wildabeast
应删除上述答案的第一部分。 “实例位置”只是“工作空间”的另一个名称,而这不是所要求的。第二部分是正确的答案。 - alphakermit


它应该是

Platform.getInstallLocation().getURL()

4
2017-07-16 07:54