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 閱讀(1807) 評論(0) 編輯 收藏 所屬分類: Eclipse接口