Java – how do I reference property files in executable jars and eclipse?

I use two properties files: log4j Properties and myapp properties. I want to load my applications correctly when I execute them in eclipse and executable jars

ATM files are stored here: / SRC / configs / * properties. I refer to them in this line with my code:

config = new PropertiesConfiguration(getClass().getResource("/configs/myapp.properties"));

This is useful if I execute my application in eclipse, but if I execute an executable jar (generated from eclipse), it will fail I created a manifest file in / meta inf / and wrote this line to it:

Class-Path: .

In order to implement, the execution of jar still fails: - (where do I have to place my property files, and how do I reference them?

If I execute jars and in my project, if I'm in eclipse, can it also reference them outside of jars? thank you!

Solution

The way you try to load the properties file is good for me Have you checked that the properties file is actually part of the generated jar file?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>