我在运行可执行 .jar 文件时遇到问题。我创建了一个包含 .properties 文件的项目。当我从 eclipse 启动它时它工作得很好,但是当我将它导出到可执行 .jar 文件并尝试运行它时:
java -jar myfile.jar
我得到以下异常:
(无法在此处发布图片) http://imageshack.us/photo/my-images/824/29583616.png/
我检查了 .jar 中的 list 文件,它包含
Class-Path: .
这是属性文件加载:
properties = new Properties();
properties.load(new FileInputStream(
"src/com/resources/treeView.properties"));
知道是什么导致了这个异常吗?
最佳答案
如果属性文件在 jar 文件中,则不能将其作为文件访问。
您需要要求类加载器将资源作为输入流获取。参见 Getting the inputstream from a classpath resource (XML file)
关于java - 由于 .properties 文件加载,可执行 .jar 无法启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11169971/