假設我有一個可執行的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