从Eclipse插件中读取资源
来源:互联网 发布:pyqt5 for windows 编辑:程序博客网 时间:2024/04/30 10:38
可以通过Eclipse里的OSGi的Bundle类,获取插件目录下的某个文件的输入流:
1. Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
2. URL url = bundle.getResource("/icon/xx.txt");
3. InputStream is = FileLocator.toFileURL(url).openStream();
从Bundle查找资源:
Bundle bundle = Platform.getBundle(pluginId);
URL fullpathString = BundleUtility.find(bundle, filePath);
Enumeration org.osgi.framework.Bundle.findEntries(String path, String filePattern, boolean recurse)
Returns entries in this bundle and its attached fragments. This bundle's
class loader is not used to search for entries. Only the contents of this bundle
and its attached fragments are searched for the specified entries. If this
bundle's state is INSTALLED, this method must attempt to resolve
this bundle before attempting to find entries.
This method is intended to be used to obtain configuration, setup,
localization and other information from this bundle. This method takes into
account that the "contents" of this bundle can be extended with fragments. This
"bundle space" is not a namespace with unique members; the same entry name can
be present multiple times. This method therefore returns an enumeration of URL
objects. These URLs can come from different JARs but have the same path name.
This method can either return only entries in the specified path or recurse into
subdirectories returning entries in the directory tree beginning at the
specified path. Fragments can be attached after this bundle is resolved,
possibly changing the set of URLs returned by this method. If this bundle is not
resolved, only the entries in the JAR file of this bundle are returned.
Examples: // List all XML files in the OSGI-INF directory and below
Enumeration e = b.findEntries("OSGI-INF", "*.xml", true);
// Find a specific localization file
Enumeration e = b
.findEntries("OSGI-INF/l10n", "bundle_nl_DU.properties", false);
if (e.hasMoreElements())
return (URL) e.nextElement();
Note: Jar and zip files are not required to include directory entries. URLs to directory entries will not be returned if the bundle contents do not contain directory entries. Parameters: path The path name in which to look. The path is always relative to the root of this bundle and may begin with "/". A path value of "/" indicates the root of this bundle. filePattern The file name pattern for selecting entries in the specified path. The pattern is only matched against the last element of the entry path. If the entry is a directory then the trailing "/" is not used for pattern matching. Substring matching is supported, as specified in the Filter specification, using the wildcard character ("*"). If null is specified, this is equivalent to "*" and matches all files. recurse If true, recurse into subdirectories. Otherwise only return entries from the specified path. Returns: An enumeration of URL objects for each matching entry, or null if an entry could not be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE], and the Java Runtime Environment supports permissions. The URLs are sorted such that entries from this bundle are returned first followed by the entries from attached fragments in ascending bundle id order. If this bundle is a fragment, then only matching entries in this fragment are returned.
1. Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
2. URL url = bundle.getResource("/icon/xx.txt");
3. InputStream is = FileLocator.toFileURL(url).openStream();
从Bundle查找资源:
Bundle bundle = Platform.getBundle(pluginId);
URL fullpathString = BundleUtility.find(bundle, filePath);
Enumeration org.osgi.framework.Bundle.findEntries(String path, String filePattern, boolean recurse)
Returns entries in this bundle and its attached fragments. This bundle's
class loader is not used to search for entries. Only the contents of this bundle
and its attached fragments are searched for the specified entries. If this
bundle's state is INSTALLED, this method must attempt to resolve
this bundle before attempting to find entries.
This method is intended to be used to obtain configuration, setup,
localization and other information from this bundle. This method takes into
account that the "contents" of this bundle can be extended with fragments. This
"bundle space" is not a namespace with unique members; the same entry name can
be present multiple times. This method therefore returns an enumeration of URL
objects. These URLs can come from different JARs but have the same path name.
This method can either return only entries in the specified path or recurse into
subdirectories returning entries in the directory tree beginning at the
specified path. Fragments can be attached after this bundle is resolved,
possibly changing the set of URLs returned by this method. If this bundle is not
resolved, only the entries in the JAR file of this bundle are returned.
Examples: // List all XML files in the OSGI-INF directory and below
Enumeration e = b.findEntries("OSGI-INF", "*.xml", true);
// Find a specific localization file
Enumeration e = b
.findEntries("OSGI-INF/l10n", "bundle_nl_DU.properties", false);
if (e.hasMoreElements())
return (URL) e.nextElement();
Note: Jar and zip files are not required to include directory entries. URLs to directory entries will not be returned if the bundle contents do not contain directory entries. Parameters: path The path name in which to look. The path is always relative to the root of this bundle and may begin with "/". A path value of "/" indicates the root of this bundle. filePattern The file name pattern for selecting entries in the specified path. The pattern is only matched against the last element of the entry path. If the entry is a directory then the trailing "/" is not used for pattern matching. Substring matching is supported, as specified in the Filter specification, using the wildcard character ("*"). If null is specified, this is equivalent to "*" and matches all files. recurse If true, recurse into subdirectories. Otherwise only return entries from the specified path. Returns: An enumeration of URL objects for each matching entry, or null if an entry could not be found or if the caller does not have the appropriate AdminPermission[this,RESOURCE], and the Java Runtime Environment supports permissions. The URLs are sorted such that entries from this bundle are returned first followed by the entries from attached fragments in ascending bundle id order. If this bundle is a fragment, then only matching entries in this fragment are returned.
0 0
- 从Eclipse插件中读取资源
- 从资源读取数据到文件中
- 从资源中读取图片 GDI+
- 从jar包中读取资源文件
- 从jar包中读取资源文件
- 从jar包中读取资源文件
- 从jar包中读取资源文件
- 从jar包中读取资源文件
- 从Jar包中读取资源文件
- 从oracle中读取blob图片资源
- 从jar包中读取资源文件
- 在Eclipse中读取资源或文件
- Eclipse中SVN插件安装附带资源
- eclipse插件开发中资源释放问题
- 插件62:从表中读取信息
- Eclipse插件项目中读取文件
- Eclipse 资源文件插件
- Eclipse插件资源链接
- 人见人爱A^B之解题思路
- Android中的ipc——binder
- 2012-12-14 16:38 hibernate 实体映射文件中 写 hql/sql 语句
- 在Centos6.5 64bit上配置pptpd VPN
- [数据结构] 迷宫问题(栈和队列,深搜和广搜)
- 从Eclipse插件中读取资源
- 问题:imtool读入的图像数据行列为什么是反着的?(已解决)
- strut2 自定义文件上传错误信息
- Sqlite3 命令行下中文乱码
- 聪明的大脑 少碰以下的食物!!
- 远程调试Eclipse插件的设置
- LCA
- 用C#模拟 Java Bean (七) —— 里程碑的思考
- 深入了解Struts2返回JSON数据的原理及具体应用范例