从Eclipse插件中读取资源
可以通过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.
从Eclipse插件中读取资源的更多相关文章
- java 从jar包中读取资源文件
在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...
- (转)java 从jar包中读取资源文件
(转)java 从jar包中读取资源文件 博客分类: java 源自:http://blog.csdn.net/b_h_l/article/details/7767829 在代码中读取一些资源文件 ...
- 深入jar包:从jar包中读取资源文件getResourceAsStream
一.背景 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等). 在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不 ...
- 【解惑】深入jar包:从jar包中读取资源文件
[解惑]深入jar包:从jar包中读取资源文件 http://hxraid.iteye.com/blog/483115 TransferData组件的spring配置文件路径:/D:/develop/ ...
- 2018-10-10 在浏览器插件中读取JSON资源文件
续前文: 浏览器插件实现GitHub代码翻译原型演示 此改进只为演示: 词典数据提取到json文件 · program-in-chinese/webextension_github_code_tran ...
- [Java基础] 深入jar包:从jar包中读取资源文件
转载: http://hxraid.iteye.com/blog/483115?page=3#comments 我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等).在单独运行的时候这些简单的 ...
- 深入jar包:从jar包中读取资源文件
我们常常在代码中读取一些资源文件(比如图片,音乐,文本等等).在单独运行的时候这些简单的处理当然不会有问题.但是,如果我们把代码打成一个jar包以后,即使将资源文件一并打包,这些东西也找不出来了.看看 ...
- Java/JavaWeb中读取资源文件
1.一般工程中使用I/O类指定文件的绝对路径读取 FileInputStream fis = new FileInputStream("src/main/resources/zsm.prop ...
- 从jar中读取资源文件的问题
在项目中遇到了一个问题,在IDE中读取配置文件的程序,打成架包以后,放到服务器上跑,报找不到资源文件的错误. 其中,资源文件的路径如下: 获取配置文件路径和读取的方法如下: private stati ...
随机推荐
- Python中模块json与pickle的功能介绍
json & pickle & shelve 1. json的序列化与反序列化 json的使用需要导入该模块,一般使用import json即可. json的序列化 方法1:json. ...
- java的迭代器详解
迭代器的引出 在jdk1.5版本之前是没有 foreach的,然而1.5版本就加上了foreach,而引入的新的foreach功能并不是在jvm上进行改进的因为代价太高,甲骨文工程师想到了一个比较好的 ...
- Xcode8 添加PCH文件
转自默默desire 1.) 打开你的Xcode工程. 在Supporting Files目录下,选择 File > New > File > iOS > Other > ...
- LeetCode 2
No1 Given a sorted array and a target value, return the index if the target is found. If not, return ...
- 【Java关键字-Interface】为什么Interface中的变量只能是 public static final
三个关键字在接口中的存在原因:public:接口可以被其他接口继承,也可以被类实现,类与接口.接口与接口可能会形成多层级关系,采用public可以满足变量的访问范围: static:如果变量不是sta ...
- Jvm原理剖析与调优之内存结构
一些不得不说的概念 JVM JVM是一种用于计算设备的规范,它是一个虚构出来的计算机,是通过在实际的计算机上仿真模拟各种计算机功能来实现的.Java虚拟机包括一套字节码指令集.一组寄存器.一个栈.一个 ...
- 3.2 2-dim Vector Initialization
声明3行4列的数组 const int m = 3, n = 4; vector<vector<int> > A(m); // 3 rows for(int i = 0; i ...
- nginx 网络模型,cpu亲和等优点
nginx优点1.IO多路复用epollIO多路复用:多个描述符的I/O操作都能在一个线程内并发交替地顺序完成,这里的"复用" 指的是复用同一个线程epollIO多路复用的实现方式 ...
- C++笔记007:易犯错误模型——类中为什么需要成员函数
先看源码,在VS2010环境下无法编译通过,在VS2013环境下可以编译通过,并且可以运行,只是运行结果并不是我们期待的结果. 最初通过MyCircle类定义对象c1时,为对象分配内存空间,r没有初始 ...
- React 系列教程 1:实现 Animate.css 官网效果
前言 这是 React 系列教程的第一篇,我们将用 React 实现 Animate.css 官网的效果.对于 Animate.css 官网效果是一个非常简单的例子,原代码使用 jQuery 编写,就 ...