【发布时间】:2012-08-16 09:21:46
【问题描述】:
假设我有一个可执行 jar 文件的 MANIFEST.MF 的以下摘录:
Manifest-Version: 1.0
Main-Class: com.intersportleitner.skischule.gui.window.SkischulApplicationWindow
Class-Path: .
...
不应该有这样的目录结构吗:
Appdir
|- bla.jar (self-executable)
|- x.properties
|- y.properties
因为如果我尝试使用以下代码片段加载属性,我会得到一个 IOException: Stream closed in properties.load(stream):
Properties properties = new Properties();
InputStream istream=SkischulApplicationWindow.class.getClassLoader().getResourceAsStream("y.properties");
BufferedInputStream stream = new BufferedInputStream(istream);
properties.load(stream);
stream.close();
该异常有点误导,因为实际上 istream 为空(指出当我试图调用 istream 的方法进行测试时...),所以找不到属性文件,我不知道为什么失败是因为根据Executable jar won't find the properties files 它应该以这种方式工作......
【问题讨论】:
-
你是用AppDir作为执行目录吗?我的意思是,你在执行:
java -jar bla.jarstanding 在那个目录上吗?