gpt4 book ai didi

java - 如何从可执行 jar 读取本地属性文件?

转载 作者:行者123 更新时间:2023-12-01 04:21:28 27 4
gpt4 key购买 nike

我在 Eclipse Indigo 上开发并测试了我的程序。运行时找到属性文件没有问题。我使用 Eclipse 导出创建了一个可运行的 jar。当程序从 jar 运行时,程序找不到属性文件。属性文件不在 jar 中,它位于部署 jar 的目录的子目录中。如上所述,该目录位于 Eclipse 运行配置中的类路径上。

C:/myApp/myApp.jar C:/myApp/properties/myApp.properties

props.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("myApp.properties"));

我是否只需要编辑 Jar list 即可将配置目录放在类路径上?

最佳答案

properties.load(this.getClass().getResourceAsStream(configFileSrc));

这应该有效。

就我而言,configFileSrc =“/apiconfig/appconfig.properties”

enter image description here

我必须在构建路径中添加staticresources目录。

谢谢

关于java - 如何从可执行 jar 读取本地属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18859617/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com