终于找到直接可以用的了
path = FileLocator.toFileURL(
Platform.getBundle(IAppConstants.APPLICATION_ID)
.getEntry("")).getPath().toString();
RCP 文件路径问题
String path =FileLocator.toFileURL(Platform.getBundle("工程名").getEntry("")).getPath
得到eclipse rcp plugin 内目录文件绝对路径的方法
import java.io.IOException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import com.work.base.exception.DataException;
import com.work.view.Activator;
public class BundlePathUtil {
public static String getRealPath(String bundleID, String entry)
throws DataException {
URL urlentry;
String strEntry;
try {
Bundle bundle = Platform.getBundle(bundleID);
if (bundle==null)
throw new DataException("请检查文件的路径",new NullPointerException());
// get path URL
urlentry = bundle.getEntry(entry);
if (urlentry==null)
throw new DataException("请检查文件的路径",new NullPointerException());
strEntry = FileLocator.toFileURL(urlentry).getPath();
} catch (IOException e1) {
throw new DataException("请检查文件的路径", e1);
}
return strEntry;
}
public static String getPluginPath(){
return Activator.getDefault().getStateLocation().makeAbsolute().toFile().getAbsolutePath();
}
}
另外,获取插件/rcp 的workspace的路径:
Platform.getInstanceLocation().getURL().getPath()
从插件/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();
}
分享到:
相关推荐
rcp editor实例的项目代码,eclipse插件开发2,观察观察,学习学习
我自己在RCP上开发的学生成绩管理系统,非常适合初学者,希望对需要的朋友有所帮助。
Eclipse RCP 应用系统开发方法与实战 源代码
eclipse rcp应用系统开发方法与实战源代码.zip
rcp editor实例的项目代码,eclipse插件开发,可以下载来学习一下
Eclipse RCP深入浅出这本书很不错,但奈何网上都是些电子版,想要找到与它配套的源代码那是相当的头疼,这里提供了中英文电子版书及配套代码供大家使用,大家可以方便的学习。
ECLIPSE RCP开发的一个程序。项目名称为:学校学生管理系统 内有项目源代码。
非常好的一本JAVA RCP入门实战的书,兼顾理论和实战。
eclipse rcp应用系统开发 方法与实践 随书源代码
关于RCP的资料 关于RCP的资料
RCP&OSGI;
基于RCP和velocity的java代码生成器 该代码生成器只可用于mysql数据库 版权公司所有 仅供交流学习 注意:请把templates文件下的模板拷贝到C:根目录下 各类都有注释 JDK6 Myeclipse6开发
RCP在线升级RCP在线升级RCP在线升级RCP在线升级RCP在线升级
eclipse rcp应用系统开发 随书源代码
该手册以本人的RCP项目介绍,如果将开发的产品,如VB JAVA RCP 等单机版本软件,需要打成成exe可以执行的文件
RCP与GEF的课件,简单的介绍了RCP和GEF中的各组件的功能,已经工作流程
15.3.使jar在你的运行路径里有效 119 16.提示和策略 120 16.1.控制台日志 120 16.2.保存用户的布局 121 16.3.获得display 122 16.4.使用eclipse的“保存”action 123 16.5.装载模型 127 16.6.向你的...
Eclipse RCP 软件打包发布方法。之前花了5分下了一个教材,更不不好用。现在自己摸索写了一个,绝对赞~
RCP的VIEWER和EDITOR做成的压缩包,可以下载了看看,是转载了别人的,不过忘了哪弄的了
Eclipse RCP应用系统开发方法与实战(源代码)