[置顶] 欢迎您。今天是2023年03月30日。

从插件中获得绝对路径:

ActivatorPlugin.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath());

通过文件得到Project:

IProject project = ((IFile)o).getProject();

通过文件得到全路径:

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

得到整个Workspace的根:

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

从根来查找资源:

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

从Bundle来查找资源:

Bundle bundle = Platform.getBundle(pluginId);

URL fullPathString = BundleUtility.find(bundle, filePath);

得到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();

}

您可能也喜欢

今天给RCP打包测试,遇到了以前的遗留问题,就是打包后配置文件丢失,导致一些功能实现不了,从而用了硬编码实现,今天闲来无事,偶然间把问题解决了。以前用的配置文件格式是ini的,在查看了几个配置文件都是properties格式能打包进去后,我也把ini改成了properties,竟然成功。呵呵~爽啊~

http://lopica.sourceforge.net/quick.html

二维码
摄像头