假设我有一个可执行的JAR文件的MANIFEST.MF以下摘录:自我可执行的JAR和外部的财产文件
Manifest-Version: 1.0
Main-Class: com.intersportleitner.skischule.gui.window.SkischulApplicationWindow
Class-Path: .
...
它不应该有可能有这样的目录结构:
Appdir
|- bla.jar (self-executable)
|- x.properties
|- y.properties
因为如果我尝试用下面的代码片段,我收到了IOException的加载性能:流在properties.load关闭(流):
Properties properties = new Properties();
InputStream istream=SkischulApplicationWindow.class.getClassLoader().getResourceAsStream("y.properties");
BufferedInputStream stream = new BufferedInputStream(istream);
properties.load(stream);
stream.close();
这个例外有点让人误解,因为实际上istream为null(注意,因为我试图调用istream的方法用于测试目的......),所以没有找到属性文件,我不知道为什么它失败,因为根据Executable jar won't find the properties files应该以这种方式工作...
是否使用APPDIR作为执行目录?我的意思是,你正在执行:'java -jar bla.jar' *站在*那个目录下? – helios 2012-08-16 09:24:21