`
hiwings
  • 浏览: 58046 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

RCP的文件路径

阅读更多

长久以来一直为RCP的文件路径获取在IDE环境时和产品发布时不同苦恼不已,今天终于可以宣布已经fix了这个难题。 
检测报告如下:
在 eclipse中运行时得到的路径结果:
Platform.getLocation().toString():E:/Eclipse/runtime-operationtool.product
Platform.getProduct().getDefiningBundle().getLocation():initial@reference:E:/Eclipse/workspace/operationtool/
Activator.getDefault().getBundle().getLocation():initial@reference:E:/Eclipse/workspace/operationtool/
Platform.getLogFileLocation():E:/Eclipse/runtime-operationtool.product/.data/.log
Platform.getInstallLocation():/D:/Program Files/eclipse/
Platform.getStateLocation(Activator.getDefault().getBundle()):E:/Eclipse/runtime-operationtool.product/.data/.plugins/operationtool
Platform.getUserLocation():/C:/Documents and Settings/Allen/user/
Platform.getInstanceLocation():/E:/Eclipse/runtime-operationtool.product/
Platform.getConfigurationLocation():/E:/Eclipse/workspace/.data/.plugins/org.eclipse.pde.core/operationtool.product/ 
在发布后运行时得到的路径结果,operationtool_1.0.0.jar未解压:
Platform.getLocation().toString():E:/product/tool/workspace
Platform.getProduct().getDefiningBundle().getLocation():initial@reference:plugins/operationtool_1.0.0.jar/
Activator.getDefault().getBundle().getLocation():initial@reference:plugins/operationtool_1.0.0.jar/
Platform.getLogFileLocation():E:/product/tool/workspace/.data/.log
Platform.getInstallLocation():/E:/product/tool/
Platform.getStateLocation(Activator.getDefault().getBundle()):E:/product/tool/workspace/.data/.plugins/operationtool
Platform.getUserLocation():/C:/Documents and Settings/Allen/user/
Platform.getInstanceLocation():/E:/product/tool/workspace/
Platform.getConfigurationLocation():/E:/product/tool/configuration/

 在发布后运行时得到的路径结果,operationtool_1.0.0.jar已解压,并删除 operationtool_1.0.0.jar:
Platform.getLocation().toString():E:/product/tool/workspace
Platform.getProduct().getDefiningBundle().getLocation():initial@reference:plugins/operationtool_1.0.0/
Activator.getDefault().getBundle().getLocation():initial@reference:plugins/operationtool_1.0.0/
Platform.getLogFileLocation():E:/product/tool/workspace/.data/.log
Platform.getInstallLocation():/E:/product/tool/
Platform.getStateLocation(Activator.getDefault().getBundle()):E:/product/tool/workspace/.data/.plugins/operationtool
Platform.getUserLocation():/C:/Documents and Settings/Allen/user/
Platform.getInstanceLocation():/E:/product/tool/workspace/
Platform.getConfigurationLocation():/E:/product/tool/configuration/

通过对检测报告分析,得出以下有用的几个API的结论:
1.product的根目录获取:
未发布前:
Activator.getDefault().getBundle().getLocation(), 截去掉 initial@reference:file :后使用,比如:E:/Eclipse/workspace/operationtool/
发布后:
Platform.getInstallLocation() ,比如:E:/product/tool/ 
2.自己定制的plugin目录的获取:
发布后:
Activator.getDefault().getBundle().getLocation(), 截去掉 initial@reference:file :后使用,当plugin未解压:/E:/product/tool/plugins/operationtool_1.0.0.jar/
当 operationtool_1.0.0.jar已解压,并删除operationtool_1.0.0.jar,得到的结果为/E:/product /tool/plugins/operationtool_1.0.0/ 
3.configuration目录的获取:
发布后:
Platform.getConfigurationLocation() ,比如/E:/product/tool/configuration/
4.workspace目录的获取:
发布后:
Platform.getInstanceLocation(), 比如/E:/product/tool/workspace/ 

.号发布前代表src,发布后忽略 
----------------------------------- 以下为参考文档-----------------------------------------------------
从插件/RCP中 取得文件路径的方法 
最近社区 里问这个问题的人特别多,所以在这里将自己用到的几个方法写出来。假如以后还有其他的方法,会进行更新。

从插件中获得绝对路径:
AaaaPlugin.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();

得到runtimeworkspace:
Platform.getInstanceLocation().getURL().getPath();

从编辑器来获得编辑文件
IEditorPart editor  =  ((DefaultEditDomain)(parent.getViewer().getEditDomain())).getEditorPart();
IEditorInput input  =  editor.getEditorInput();
if (input  instanceof  IFileEditorInput)  {
IFile file  =  ((IFileEditorInput)input).getFile();
}


分享到:
评论

相关推荐

    Eclipse RCP详细教程

    目 录 1.富客户端平台 1 1.1.概述 1 1.2.Eclipse RCP 建设风格——插件,...22.附录:配置文件 152 22.1.概述 152 22.2..project 153 22.3.Manifest.MF 154 23.附录:使用接口技术 154 23.2.Jface 154

    开发项目用SWING与RCP与SWT.JFACE的分析

    SWT是作为Eclipse开发环境的一个插件形式存在,可以在${你的eclipse安装路径}\plugins路径下的众多子目录下去搜索SWT.JAR文件,在找到的JAR文件中包含了SWT全部的Java类文件。因为SWT应用了JNI技术,因此同时也要...

    Eclipse RCP Plug-in开发自学教程(Eclipse3.6)

    最近抽些时间,更新到eclipse3.6上来,既作为为广大Eclipser入门plugin/RCP开发的一个方便之门,也是对自己近年来学习的一个总结吧。 每一章都会单独提取出来,并尽可能的独立于其他章节,更新中的源代码工程也会...

    Eclipse RCP Plugin 开发自学入门指南(CEC首发)

    1.3 RCP与PLUGIN ................................................................................................................................ 9 2 创建第一个RCP程序 ....................................

    eclipse-RCP-3.1.1-win32.zip

    用于 eclipse 的JFace编程,解压它,然后对它eclipse/plugins下的所有文件构造路径

    打开文件(目录)所在目录 Eclipse 插件

    打开文件(目录)所在目录 Eclipse 插件 ALT+D 迅速定位到所在文件夹

    pwd命令 显示当前路径

    pwd命令是“print working directory”中每个单词的首字母缩写,其功能正如所示单词一样,为打印...与该功能相关的Linux命令:touch命令 – 创建文件rcp命令 – 远程文件复制awk命令 – 文本和数据进行处理的编程语言nm

    Linux指令一周通 (技术图书大系).azw3

    1.65 rcp指令:远程复制文件或目录 1.66 rhmask指令:产生加密文件 1.67 rm指令:删除文件或目录 1.68 tac指令:反序输出文件 1.69 tar指令:打包同时压缩/解压缩文件 1.70 tee 指令:从标准输入读取数据到标准输出...

    HP-UX系统管理(高级)

    14.2.5 rcp 命令.143 14.2.6 remsh 命令144 14.2.7 rwho命令144 14.2.8 ruptime 命令.145 14.3 修改和配置网络参数.145 14.3.1 设置IP地址和子网掩码.145 14.3.2 设置默认路由.146 14.3.3 解析主机名为IP地址.146 ...

    AIX系统管理

    4.3 路径 29 4.4 显示当前工作目录 30 4.5 改变目录层次 30 4.6 创建目录mkdir 31 4.7 删除目录rmdir 31 4.8 文件操作命令 31 4.8.1 列文件ls 31 4.8.2 文件拷贝cp 31 4.8.3 文件移动mv 32 4.8.4 文件删除rm 32 ...

    UNIX教程网络篇掌握各种Unix网络应用技术

    15.4 远程文件拷贝命令:rcp 213 15.5 远程执行命令:rsh 214 第16章 UUCP 216 16.1 UUCP的寻址方式 216 16.2 显示连接系统命令:uuname 218 16.3 UUCP连接管理命令:uucico 和uuxqt 218 16.4 UUCP命令 219 16.5 ...

    UNIX教程网络篇(打包)

    15.4 远程文件拷贝命令:rcp 213 15.5 远程执行命令:rsh 214 第16章 UUCP 216 16.1 UUCP的寻址方式 216 16.2 显示连接系统命令:uuname 218 16.3 UUCP连接管理命令:uucico 和uuxqt 218 16.4 UUCP命令 219 16.5 ...

    UNIX网络教程---如何配置Unix网络及相关功能应用

    15.4 远程文件拷贝命令:rcp 213 15.5 远程执行命令:rsh 214 第16章 UUCP 216 16.1 UUCP的寻址方式 216 16.2 显示连接系统命令:uuname 218 16.3 UUCP连接管理命令:uucico 和uuxqt 218 16.4 UUCP命令 219 16.5 ...

    入门学习Linux常用必会60个命令实例详解doc/txt

    ◆ 网络操作命令:ifconfig、ip、ping、netstat、telnet、ftp、route、rlogin、rcp、finger、mail、 nslookup; ◆ 系统安全相关命令:passwd、su、umask、chgrp、chmod、chown、chattr、sudo ps、who; ◆ 其它...

    UNIX教程网络篇

    15.4 远程文件拷贝命令:rcp 213 15.5 远程执行命令:rsh 214 第16章 UUCP 216 16.1 UUCP的寻址方式 216 16.2 显示连接系统命令:uuname 218 16.3 UUCP连接管理命令:uucico 和uuxqt 218 16.4 UUCP命令 219 16.5 ...

    relay-compiler-plus:支持持久查询的自定义中继编译器

    中继编译器加 自定义中继编译器,支持持久查询 中继现代很棒。 但是,它缺少一些东西,...是schema.graphql或schema.json文件或schema.js的路径(是的!rcp现在支持从graphql-js直接编译!)。 是src目录的路径 然

    Eclipse_Swt_Jface_核心应用_部分19

    3.2.1 设置编译后.class文件的保存目录 23 3.2.2 导入项目使用的包 25 3.2.3 设置编译方式 26 3.2.4 运行程序 27 3.3 常用的代码编辑功能 28 3.3.1 添加注释 28 3.3.2 自定义格式化代码 28 3.3.3 自动...

    Eclipse 浏览目录插件

    Eclipse 4 插件,用于在资源管理器中打开活动窗口文档所在的文件夹,或打开命令行。安装:直接放置于 Eclipse 的 dropins 目录下,重启后工具栏及左键菜单均有Smart Explore条目。

    LUH2_Data:GIS格式的LUH2数据编译和转换

    生态学家在历史,当前和未来气候... 该数据是全球性的,具有约50 km的空间分辨率,涵盖850-2300年,包括土地使用状态,过渡带和mgt层以及若干代表性集中路径(RCP)和社会经济路径(SSP)。 有关数据的更多详细信息,请

Global site tag (gtag.js) - Google Analytics