从Eclipse插件中读取资源
2014-04-26 12:56
387 查看
可以通过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.
相关文章推荐
- 从Eclipse插件中读取资源
- 从Eclipse插件中读取资源
- Eclipse插件TFS的使用 类似SVN 但是功能更强大,适应就很好用,能防止冲突使用文档在资源中
- eclipse 打开资源文件所在的文件夹插件
- Eclipse重量级插件及相关资源列表(转)
- Eclipse插件开发图片资源管理
- 学习eclipse插件开发资源全收集(plugin)
- Eclipse 3.6 插件资源
- 学习eclipse插件开发资源全收集(plugin)
- Eclipse 插件资源地址记录
- 学习eclipse插件开发资源全收集(plugin)
- Eclipse打jar包,资源文件的读取
- (转)Eclipse 3.6 插件资源-持续更新ing-更新7次--欢迎有好用插件的朋友推荐
- 学习eclipse插件开发资源全收集(plugin)
- my资源列表三 (csdn 99% 0分资源下载 -- eclipse/myeclipse 插件 专区 )
- Eclipse打jar包,资源文件的读取
- 用eclipse中的svn资源库插件打开资源库位置报错:文件夹""不存在
- 资源.Eclipse.相关插件下载地址
- I18n(国际化)原理(国际化资源文件2种实现支持中文的方法,propedit5.3.3插件在MyEclipse和Eclipse中安装)
- Eclipse插件项目中读取文件