Jar reads external and internal configuration file issues

Source: Internet
Author: User
Tags log4j

When you recently modified the XX application, it involved the need to read the project configuration file in the jar package. In the jar package, the configuration file is read and needs to be handled separately.

Some of the configuration files in the project, such as Dbconfig.properties log4j.xml do not want to be packaged into jars.

Because some of these configuration information may be modified, packaged into the jar, it becomes awkward and inconvenient to modify the file.

You can read the external configuration file in the jar package in the following way.

Method One:

Key code.

To read the properties file method:

InputStream ins = GetClass (). getResourceAsStream ("/resource/dbconfig.properties");

But Log4j.xml needs to be dealt with separately:

Propertyconfigurator.configure (System.getproperty ("User.dir") + "/resource/log4j.xml");

Method Two:

The configuration files Out.properties and Jiar packages are under the same directory:

FileInputStream inputStream1 = new FileInputStream ("out.properties");

Configuration file In.properties inside the jar package:

InputStream inputStream2 = A.class.getresourceasstream ("/in.properties");

Jar reads external and internal configuration file issues

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.