How can I get the absolute path to the Eclipse install directory?

…衆ロ難τιáo~ 提交于 2019-12-20 20:22:06

问题


I am writing an Eclipse product, composed of plugins.
In one of my plugins, I need to get the absolute path to the directory where Eclipse is installed.
(i.e. /Applications/Eclipse on Mac or C:\Program Files\Eclipse on Win).

Can't find an API for this. Ideas?


回答1:


codejammer suggests:

The following gives you the installed location

Platform.getInstallLocation().getURL()

See the 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
 */



回答2:


It should be

Platform.getInstallLocation().getURL()


来源:https://stackoverflow.com/questions/4494528/how-can-i-get-the-absolute-path-to-the-eclipse-install-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!