超越自我

一切皆有可能

 

Eclipse 文件资源路径

运行环境(runtime-workspace)下面.metadata\.plugins\xxxxxx (plugin ID)
AaaaPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());


String path = ((IFile)o).getLocation().makeAbsolute().toFile().getAbsolutePath();

 

运行环境(runtime-workspace):

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();


从根来查找资源:

IResource resource = root.findMember(new Path(containerName));

IWorkspaceRoot
 -IProject
   -IFolder
     -IFile

IResource
得到绝对路径方法:
getLocation().toOSString()
得到相对路径方法:
getFullPath().toOSString()
通过相对路径找到文件:
比如说:XXXProject下面有 "/webApp/StarflowFormEdit.jsp"
String path=pjt.getFile("/webApp/StarflowFormEdit.jsp").getLocation().toOSString();

//Project
从Bundle来查找资源:

Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, filePath);
备注:
一个OSGI模块最重要的就是Bundle和Service,我们可以认为Bundle是一种插件管理器,
主要是通过BundleActivator管理模块的生命周期,而Service则是这个模块可暴露对外的服务对象。
这里体现了OSGI和传统的Plug-in Framework不同的一个地方,管理和静态结构分开,
每个Bundle拥有自己的ClassLoader以及context,通过context可进行服务的注册、卸载等,
这些操作都会通过事件机制广播给相应的其他的Bundle;一般来说都为通过在Bundle中编写初始需要注册的服务的方法来
完成Bundle可供外部使用的服务的暴露功能。


得到Appliaction workspace:
Platform.asLocalURL(PRODUCT_BUNDLE.getEntry("")).getPath()).getAbsolutePath();

运行环境(runtime-workspace):
Platform.getInstanceLocation().getURL().getPath();

从编辑器来获得编辑文件:

IEditorPart editor = ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input = editor.getEditorInput();
if(input instanceof IFileEditorInput){
IFile file = ((IFileEditorInput)input).getFile();

posted on 2006-08-04 13:57 jame 阅读(1798) 评论(0)  编辑  收藏 所属分类: Eclipse接口


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(3)

随笔档案

文章分类

文章档案

相册

收藏夹

UML

搜索

最新评论

阅读排行榜

评论排行榜