How to read the properties file and log4j.properties outside the jar package

Source: Internet
Author: User

http://jrails.iteye.com/blog/1705464

In general, when using the properties configuration file in the project, the relevant properties file is placed in the SRC directory, after the app is packaged to generate the jar, the corresponding properties profile ...

Typically when you use the properties profile in your project, the relevant properties file is placed in the SRC directory, and the corresponding properties profile is generated in the jar package after the app is packaged to generate the jar. In this case, it is quite troublesome to modify the configuration file and re-hit the jar package.

Since this is so troublesome, you certainly want to put the configuration file in the other directory, the generated jar package does not contain the corresponding configuration file, modify the configuration file without repackaging, yes, here is a solution.

Read inside the jar package configuration file:

this. getclass (). getClassLoader (). getResourceAsStream ("/configfilename.properties

To read the jar out-of-package configuration file:

String FilePath = System.getproperty ("User.dir") + "/conf/configfilename.properties";     New Bufferedinputstream (new

In addition, if the app uses the Log4j.properties file, the default storage path is src/ Log4j.properties, as above, I want to put log4j.properties in other directories, so that you do not need to re-play the jar when modifying the log4j configuration file.

Add the following code to the first line of the main function:

        

How to read the properties file and log4j.properties outside the jar package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.