java - 由于 .properties 文件加载,可执行 .jar 无法启动

标签 java jar executable-jar properties-file

我在运行可执行 .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/

相关文章:

postgresql - java.lang.ClassNotFoundException : org. postgresql.驱动程序

java - 尝试使用命令行远程编译一个具有多个依赖项的 Java 程序,目前我只能在 Eclipse 中进行本地编译

java - .jar 文件夹如何可移植?

java - 在 Mac 上合并来自 Processing 的 JAR 文件

java - AspectJ 'around' 建议 - 你必须调用 'proceed' 吗?

java - docker 运行 nginx 加 jar

java - 如果无代码 : is it just an intellectual challenge or is it concretely useful?

java - 如何使用 Eclipse 创建自洽的 .jar 文件?

java - 在 iText 7 中实现 PdfContentByte 和 PdfTemplate 的替代方法是什么

java - 读取蓝牙数据并将其放入MainActivity