Eclipse插件开发,在工程中引用当前工程下的文件
使用Eclipse开发RCP的时候,需要引用配置文件config.xml,而该配置文件放在了当前工程下,则通过如下的代码引用:
Bundle bundle = Platform.getBundle(PLUGIN_ID);URL pluginUrl = Platform.find(bundle, new org.eclipse.core.runtime.Path("plugin.xml"));URL pluginFileUrl = Platform.asLocalURL(pluginUrl);org.eclipse.core.runtime.Path x = new org.eclipse.core.runtime.Path(pluginFileUrl.getPath());org.eclipse.core.runtime.Path y = new org.eclipse.core.runtime.Path(x.removeLastSegments(1).toString());java.io.File file = new java.io.File(y+"/config.xml");
单单为了引用一个文件,就要如此复杂,可见Eclipse插件开发设计很不人性化的,如此多的API,错综复杂,以后还是少用为妙。