Eclipse插件 - 找不到文件异常

时间:2013-06-14 07:31:35

标签: java eclipse osgi eclipse-plugin

在我的插件项目中,我添加了一个名为“database.properties”的新文件,当我尝试运行插件时,我遇到异常:

java.io.FileNotFoundException: database.properties (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)

这是我的项目结构:

enter image description here

此外,我已将该文件包含在构建属性中,此处显示了屏幕截图:

enter image description here

我尝试过清理,重新启动eclipse,构建等等。但是系统仍无法找到该文件。谁能帮我?我在这里失踪了什么?

1 个答案:

答案 0 :(得分:2)

你必须像这样访问文件:

Bundle bundle = Platform.getBundle("your_plugn_id");
InputStream is = bundle.getEntry("database.properties").openStream();

并在build.properties中包含:

bin.includes = META-INF/,\
           OSGI-INF/,\
           database.properties/,\
           .,\
           plugin.xml